$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); ?>