rendered paste body<?php
$xs = "select * from categories order by id";
$xq = mysql_query($xs) or die(mysql_error());
$xr = mysql_fetch_assoc($xq);
$xarray = array();
do{
if ($xr['main_cat'] == "0") {
$xarray[$xr['id']] = array("catid"=>$xr['id'],"category"=>$xr['category'],"child"=>'');
} else {
$xp = explode("||",$xr['ancestors']);
$parent = array();
foreach ($xp as $lxp) {
if ($lxp != "" && $lxp != 0) {
$lxp = str_replace("|","",trim($lxp),$count);
$parent []= $lxp;
}
}
$struc = '';
foreach ($parent as $parent_l) {
$struc .= "[$parent_l]['child']";
}
$xarray[$struc] = array("catid"=>$xr['id'],"category"=>$xr['category'],"child"=>'');
}
}while($xr = mysql_fetch_assoc($xq));
print_r($xarray);
?>