Thinkphp the problem of dynamically loading menus
Implementing Parent-child menu loading with two collections
foreach ($vo as $key = = $value) {
$vo [$key] [' ID ']= $value [' id '];
$vo [$key] [' MenuID ']= $value [' MenuID '];
$vo [$key] [' menuname ']= $value [' menuname '];
$vo [$key] [' ParentID ']= $value [' ParentID '];
$vo [$key] [' childID ']= $value [' childID '];
$vo [$key] [' url ']= $value [' url '];
}
}
foreach ($v 1 as $key 1=> $value 1) {
foreach ($v 2 as $key = + $value 2) {
if ($key 1+1>=count ($vo)) {
echo ' 1 ';
Break
}
if ($v 2[$key 1+1][' parentid ']== $vo [$key] [' menuid ']) {
$vo [$key 1+1][' ParentID ']= $value 2[' MenuID '];
Print_r ($vo [$key +1][' ParentID ']);
}
}
}
Dump ($VO)
Why the $vo and I think the menu directory structure is not the same ah?
------Solution--------------------
Recommended posts for Moderators: http://bbs.csdn.net/topics/390524563
------Solution--------------------
1. You can't see what you're going to do from your code.
2, if the outer loop is the parent menu, then the inner loop is to assemble the submenu data of the parent menu item
If that's the case, then your code is too inefficient.
TP provides the ability to correlate queries and return nested arrays, and does not require you to bother too much
3, the parameters passed is naturally the ID of the parent node, so that it can be successfully obtained under the ID of the first-level child node data