0

配列を取得して、親子で新しい多次元を作成しようとしています。近寄れる気がするけど、じっと見てないで。

$value->menu_item_parent //Contains the parent value that can be used for key

私は何が欠けていますか?

$the_mega = array();
foreach ($menuitems as $key => $value) {
    if ($value->menu_item_parent=='0') {
        $the_mega["parents"][]=$value->title;
    }else{
        $the_mega[$value->title]["childs"]=$value->title;
    }       
}
}
echo '<pre>';
print_r($the_mega);
echo '</pre>';

 Array
(
    [parents] => Array
        (
            [0] => Parent 1
            [1] => Parent 2
        )

    [Child 1] => Array
        (
            [childs] => Child 1
        )

    [Child 2] => Array
        (
            [childs] => Child 2
        )

    [Child 3] => Array
        (
            [childs] => Child 3
        )

)
4

1 に答える 1

0

これを試して:

$the_mega = array();
foreach ($menuitems as $key => $value) {
    if ($value->menu_item_parent=='0') {
        $the_mega[$key]['parents'][]=$value->title;
    }else{
        $the_mega[$value->title]['childs'][]=$value->title;
    }       
}
于 2013-08-06T13:55:52.047 に答える