[eluser]TheFuzzy0ne[/eluser]
I know where you're coming from. I needed to take a break from what I was doing, so here's what I came up with.
./system/application/controllers/mdarray_parse_demo.php
Code:
<?php
class Mdarray_parse_demo extends Controller
{
function Mdarray_parse_demo()
{
parent::Controller();
$this->load->library('parser');
}
function index()
{
$data['categories'] = $this->get_data();
$this->parser->parse('mdarray_parse_demo', $data);
}
function get_data()
{
return array
(
array
(
'title' => 'Category 1',
'products' => array
(
array
(
'prod_title' => 'Hammer',
'prod_description' => 'For hitting stuff',
'sub_products' => array
(
array
(
'sp_title' => 'Glass Nails',
),
array(
'sp_title' => 'Rubber Nails',
)
),
),
array
(
'prod_title' => 'Wheel Chair',
'prod_description' => 'It\'s a chair with wheels...',
'sub_products' => array
(
array
(
'sp_title' => 'Pedals',
),
array(
'sp_title' => 'Nitrous Oxide',
)
),
),
),
),
array
(
'title' => 'Category 2',
'products' => array
(
array
(
'prod_title' => 'Spade',
'prod_description' => 'For burying people',
'sub_products' => array
(
array
(
'sp_title' => 'Chloroform',
),
array(
'sp_title' => 'Meat Clever',
)
),
),
array
(
'prod_title' => 'Rocket Launcher',
'prod_description' => 'For those times when you just need to de-stress',
'sub_products' => array
(
array
(
'sp_title' => 'Bill Gates',
),
array(
'sp_title' => 'Amy Winehouse',
)
),
),
),
),
);
}
}
./system/application/views/mdarray_parse_demo.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html >
<head>
<title>Multi-dimensional Array Parse Demo</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>
{categories}
<div>
<h2>{title}</h2>
<ul>
{products}
<li>{prod_title}<br />
{prod_description}
<ul>
{sub_products}
<li>
{sp_title}
</li>
{/sub_products}
</ul>
</li>
{/products}
</ul>
</div>
{/categories}
</body>
</html>
Please see attached image for the result. I think the key is to ensure that none of the sub arrays have a key matching any of the keys in the parent arrays (hope that makes sense).