1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| $pages = array(
array('id'=>1, 'label'=>'Home', 'slug'=>'home', 'parent'=>0),
array('id'=>2, 'label'=>'About us', 'slug'=>'about-us', 'parent'=>0),
array('id'=>3, 'label'=>'Issue', 'slug'=>'issue', 'parent'=>2),
array('id'=>4, 'label'=>'Background', 'slug'=>'background', 'parent'=>2),
array('id'=>5, 'label'=>'Profile', 'slug'=>'profile', 'parent'=>2),
array('id'=>6, 'label'=>'Procedures', 'slug'=>'procedures', 'parent'=>2),
array('id'=>7, 'label'=>'Company development plan', 'slug'=>'company-development-plan', 'parent'=>2),
array('id'=>8, 'label'=>'Team', 'slug'=>'team', 'parent'=>2),
array('id'=>9, 'label'=>'Solutions', 'slug'=>'solutions', 'parent'=>0),
array('id'=>10, 'label'=>'News & events', 'slug'=>'news-events', 'parent'=>0),
array('id'=>11, 'label'=>'Partners', 'slug'=>'partners', 'parent'=>0),
array('id'=>12, 'label'=>'Contact us', 'slug'=>'contact-us', 'parent'=>0)
);
function arrayMenu($array){
$temp = array();
foreach($array as $value){
$temp2 = array();
$temp3 = array();
foreach($array as $val){
if ( $value['id'] == $val['parent'] )
array_push($temp2, $val);
}
array_push($temp, array('parent'=>$value, 'children'=>$temp2));
}
return $temp;
}
$temp = arrayMenu($pages);
echo '<pre>';
print_r($temp);
echo '</pre>'; |