我有这个数组:
$('#button-plus').click(function() {
var lastChar = $('#disp').val().slice(-1);
var firstChar = $('#disp').val().slice(0);
if (lastChar == '*' || lastChar == '-' || lastChar == '+' || lastChar == '/' || lastChar == '.' || lastChar == '(' || lastChar == '%'){
// DO NOTHING
}
else if (firstChar == '0'){
// DO NOTHING
}
else {
addChar(this.form.display, '+');
}
$('#disp').removeClass("result");
dotCount = 0;
});
正如你所看到的,我有同名的 [Label] => Array
(
[CMS] => Array
(
[CMS Settings] => CMS Settings
[Content Categories List] => Content Categories List
[Extract Pages] => Extract Pages
[Manage Affiliate] => Manage Affiliate
)
[Label] => Array
(
[CMS] => Array
(
[Manage Events] => Array
(
[Create Events] => Create Events
[Event List] => Event List
)
[Manage Highlights] => Array
(
[Highlights List] => Highlights List
[Manage Highlights] => Manage Highlights
)
[Manage Menus] => Array
(
[List Menus] => List Menus
)
[Manage News] => Array
(
[List of News] => List of News
[Manage News] => Manage News
)
[Manage Web Pages] => Array
(
[List Web Pages] => List Web Pages
[Manage Webpages] => Manage Webpages
)
)
)
在第一个重复两次,它有一个叫label
的孩子和他们的子孩等等
在第二个中,我有一个叫CMS
的孩子,其中有一个名为CMS
的子项,另一个叫Manage Event
的孩子叫Manage Event
等。
我使用此递归函数来获得此结果:
create events
所以我的问题是如何合并它们并在一个名为foreach($menu as $row){
$x[$row['parent3']][$row['parent2']][$row['parent1']][$row['pag_desc']]=$row['pag_desc'];
}
function recursive($x, $out) { if (is_array($x)){
//$out .= "<ul>";
foreach($x as $i => $data) {
if ($i === '') {
$out = recursive($data, $out);
continue;
}
$out .= "<li>";
if (is_array($data)){
$out .= ' <a href="#" class="dropdown-toggle" data-toggle="dropdown">';
}
else
{
$out .= '<a href="#">';
}
$out .= $i;
if (is_array($data)){
$out .= '<b class="caret"></b></a>';
$out .= "<ul class='dropdown-menu'>";
$out = recursive($data, $out);
$out .= "</ul></li>";
}
else
{
$out .= "</a>";
}
if (is_array($data)){
}
else
{
$out .= "</li>";
}
}
}
return $out; }
的数组下显示为父项,并在其下显示所有子项和子项
提前谢谢你