How to implement multi-level menu in the front desk of website in PHP?
我想大声告诉你
我想大声告诉你 2017-05-16 13:05:13
0
3
617

How do the front desks of most websites now implement multi-level menus? Of course, these menu data contents are controllable by the server and are in the database, rather than static on the front end

我想大声告诉你
我想大声告诉你

reply all(3)
Peter_Zhu

1. Design a menu table with fields similar to <id, url, name, pid, status> (pid is the id of the upper-level menu, the pid of the first-level menu is 0, status is whether to display, design according to your own needs)
2. The frontend generates an array structure based on the data in the table and renders it on the page
3. Of course there is a backend, how to delete, modify and check the data in the table

过去多啦不再A梦
function select_tree($tree, $id = 0, $lev = 0,$html=[]) {
  foreach ($tree as $key => $items) {
    if ($items['parent_id'] == $id) {
      $newid = $items['id'];
      //$items['id']
      $html[$items['id']] = str_repeat("&nbsp;&nbsp;",$lev) . '└─' . $items['title'];
      $html=$html + select_tree($tree, $newid, $lev+2,$html);
    }
  }
  return $html;
}
迷茫

-.- It is recommended that Baidu php Infinitus classification
php Infinitus classification

I just found one for you to look at

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template