与多级阵列的多级菜单 [英] multilevel menu with multilevel array
问题描述
只是想在这里问任何人都可以解决这个问题?
just want to ask anyone here can solve this problem?
我要创建与多级阵列产生多级菜单。
我只是无法得到完美的解决方案,它总是有array_push错误。
我的研究最初的想法来自 http://www.weberdev.com/get_example-4830.html
I want to create a multilevel menu by generate with multilevel array. I just can't get perfect solution, it always got array_push error. My study the original idea come from http://www.weberdev.com/get_example-4830.html
但仍不能满足我的需要。
But still cannot match my need.
这是我的MySQL
[code]
-----------------------------------------
|id | parent_id| name | link |seq
|1 | 0 |dashboad |dashboard/|1
|2 | 0 |menu1 |menu1/ |2
|3 | 0 |menu2 |menu2/ |3
|4 | 0 |menu3 |menu3/ |4
|5 | 2 |add |add/ |1
|6 | 3 |add |add/ |1
|7 | 2 |edit |edit/ |2
|8 | 4 |add |add/ |1
------------------------------------------
[/code]
我想我的数组一些这样的事
I want my array some thing like this
array('dashboard'=>array(
'id'=>'',
'name'=>'dashboard',
'title'=>'dashboard',
'permalink'=>base_url().'dashboard/',
'active'=>FALSE,
'child'=>NULL
),
'menu1'=>array(
'id'=>'',
'name'=>'menu1',
'title'=>'menu1',
'permalink'=>base_url().'menu1/',
'active'=>FALSE,
'child'=>array(
'add'=>array(
'id'=>'',
'name'=>'add',
'title'=>'add',
'permalink'=>base_url().'menu1/add',
'active'=>FALSE,
'child'=>NULL
),
'edit'=>array(
'id'=>'',
'name'=>'edit',
'title'=>'edit',
'permalink'=>base_url().'menu1/edit/',
'active'=>FALSE,
'child'=>NULL
)
),
),
...................[similar like above]
);
我唯一能够做,直到push_array,但它警告
警告:array_push()[function.array推]:第一个参数应该是一个数组
I only able to do until push_array, but it has warning Warning: array_push() [function.array-push]: First argument should be an array
我有这个问题已经有很多讨论,但我做了一些研究之后,大部分的情况下都在做多级菜单,但在一个水平阵列。我想实现的东西多级阵列。任何人都可以帮忙吗?
I have this question had been discuss with a lot, but after I do some research most of the case are doing multilevel menu but in one level array. I want to achieve something multilevel array. Anyone can help?
临时数组我使用静态类型。
The temporary array I am using static type.
推荐答案
[解决]
我要声明数组第一之前,我推,否则PHP不能推里面的数据,这将是空的。感谢主!
I have to declare the array first before I push it, else PHP can't push the data inside, it will be empty. Praise the Lord!
if(!isset($option_results[$nav_ParentName]['child']))
{
$option_results[$nav_ParentName]['child'] = array();
}
$option_results[$nav_ParentName]['child'] = $option_results[$nav_ParentName]['child'] + $temp;
但对于这个解决方案的事情是不能声明数组$ ['孩子'] = NULL;
but the thing for this solution is cannot declare $array['child'] = null;
这篇关于与多级阵列的多级菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!