我想使用PHP
创建动态多维数组我需要像这样生成数组......
$fetchMenu = array('page-1' => array(
'name' => 'first_page',
'label' => 'First page 2',
'route' => 'product_index',
'pages' => array(
array(
'name' => 'xxx',
'label' => 'xxx',
'route' => 'product_index',
), array(
'id' => 'permissions',
'label' => 'Permissions',
'title' => 'Permissions',
'route' => 'product_add',
'menu_tree_path' => 'default|system|roles_and_permission|permissions',
'display_in_menu' => true,
)
),
),
'page-2' => array(
'name' => 'second_page',
'label' => 'Second page 2',
'route' => 'product_index',
'pages' => array(),
),);
我该怎么做?
答案 0 :(得分:0)
这样的事情?
$dynMenu = array();
$bookLength = 5; //function getBookLength() ??
for($i=0;$i<$bookLength;$i++){
$pageNumber = 'page'.$i;
$page = $i; // function getPages() ??
$dynMenu[$pageNumber] = array('name' => 'foo', 'label' => 'bar');
for($j=0;$j<$page;$j++){
$dynMenu[$pageNumber][$j] = array('name' => 'foo-ish', 'label' => 'bar-ish');
}
}