Hello folks,
have a little problem with constructing a multidimensional array.
have a database that contains two tables, one is used as category index, the other one containes the category items.
The category index contains 3 fields: id, cat_id, cat_name.
the cat_id is a representation of the positions in the category tree and looks as follows:
Eg: 103025 means that the category is located at the 25th position level 3, which is a subcat. of the 3rd category at level 2, which is a subcat of the 1st category at level 1 of the tree.
OK, now the problem:
I retrieve the data from the index table which results in an array containing the cat_id and the cat_name. Then I use explode to split the cat_id, something like this:
$cat = explode("0", $row['cat_id']);
Keeping the example above the resulting array may look like this:
$cat( [0] => "1", [1] =>"3", [2] => "25");
Now I want to construct a multidimensional result Array may look like this:
$result([1] => Array( [dummy] => "dummy" //to initialize the structure
[cat_name] => "1stCat"
[cat_items] => Array([1] => ([item_name] => "1stItem", [description] =>"1stDecr"), [2] => (......))
[subcat] => Array([dummy] => "dummy", [1] => Array([subcat_name] => "subcat1", ....)
etc,etc, etc)
Hope this looks at least a little clear.
Well, and this construction is the problem. The construction of the partial arrays might not be the problem, but how should I merge the partial arrays correctly to where they belong in the result array to represent the tree.
Can anybody help me with this?
Thanks in advance.
Best regards
Gaucho