递归无限分类 connect_errno) { die('连接错误信息:' . mysqli_connect_error()); } //mysqli设置字符集 $mysqli-set_charset('utf8'); $sql = "select * from t_navlink where pid = $id"; $result = $mysqli-query($sql); $arr = array(
connect_errno) { die('连接错误信息:' . mysqli_connect_error()); } //mysqli设置字符集 $mysqli->set_charset('utf8'); $sql = "select * from t_navlink where pid = $id"; $result = $mysqli->query($sql); $arr = array(); if ($result && $mysqli->affected_rows) {//如果有子类 while ($rows = $result->fetch_assoc()) { //循环记录集 $rows['list'] = get_array($rows['id']); //调用函数,传入参数,继续查询下级 $arr[] = $rows; //组合数组 } return $arr; } } $list = get_array(0); //调用函数 //var_dump($list); //输出数组 echo json_encode($list);