🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# :-: 多维数组查询 ``` $arr = array( array("id" => 1, "pid" => 0, 'cat' => '栏目一'), array("id" => 2, "pid" => 0, 'cat' => '栏目二'), array("id" => 3, "pid" => 1, 'cat' => '栏目三'), array("id" => 4, "pid" => 2, 'cat' => '栏目四'), array("id" => 5, "pid" => 1, 'cat' => '栏目五'), array("id" => 6, "pid" => 5, 'cat' => '栏目六'), array("id" => 7, "pid" => 5, 'cat' => '栏目七'), array("id" => 8, "pid" => 6, 'cat' => '栏目八'), array("id" => 9, "pid" => 1, 'cat' => '栏目九'), array("id" => 10, "pid" => 0, 'cat' => '栏目十'), array("id" => 11, "pid" => 10, 'cat' => '栏目十一'), array("id" => 12, "pid" => 11, 'cat' => '栏目十二'), array("id" => 13, "pid" => 2, 'cat' => '栏目十三'), array("id" => 14, "pid" => 13, 'cat' => '栏目十四') ); $info = app::md_in_array('栏目一', $arr); var_dump($info); ``` 打印输出为 ``` array(3) { ["id"]=> int(1) ["pid"]=> int(0) ["cat"]=> string(9) "栏目一" } ``` ***** # :-: 生成无限极分类树 ``` $arr = array( array("id" => 1, "pid" => 0, 'cat' => '栏目一'), array("id" => 2, "pid" => 0, 'cat' => '栏目二'), array("id" => 3, "pid" => 1, 'cat' => '栏目三'), array("id" => 4, "pid" => 2, 'cat' => '栏目四'), array("id" => 5, "pid" => 1, 'cat' => '栏目五'), array("id" => 6, "pid" => 5, 'cat' => '栏目六'), array("id" => 7, "pid" => 5, 'cat' => '栏目七'), array("id" => 8, "pid" => 6, 'cat' => '栏目八'), array("id" => 9, "pid" => 1, 'cat' => '栏目九'), array("id" => 10, "pid" => 0, 'cat' => '栏目十'), array("id" => 11, "pid" => 10, 'cat' => '栏目十一'), array("id" => 12, "pid" => 11, 'cat' => '栏目十二'), array("id" => 13, "pid" => 2, 'cat' => '栏目十三'), array("id" => 14, "pid" => 13, 'cat' => '栏目十四') ); $info = app::category($arr); var_dump($info); ``` 打印结果为 ``` array(3) { [0]=> array(4) { ["id"]=> int(1) ["pid"]=> int(0) ["cat"]=> string(9) "栏目一" ["subcat"]=> array(3) { [0]=> array(3) { ["id"]=> int(3) ["pid"]=> int(1) ["cat"]=> string(9) "栏目三" } [1]=> array(4) { ["id"]=> int(5) ["pid"]=> int(1) ["cat"]=> string(9) "栏目五" ["subcat"]=> array(2) { [0]=> array(4) { ["id"]=> int(6) ["pid"]=> int(5) ["cat"]=> string(9) "栏目六" ["subcat"]=> array(1) { [0]=> array(3) { ["id"]=> int(8) ["pid"]=> int(6) ["cat"]=> string(9) "栏目八" } } } [1]=> array(3) { ["id"]=> int(7) ["pid"]=> int(5) ["cat"]=> string(9) "栏目七" } } } [2]=> array(3) { ["id"]=> int(9) ["pid"]=> int(1) ["cat"]=> string(9) "栏目九" } } } [1]=> array(4) { ["id"]=> int(2) ["pid"]=> int(0) ["cat"]=> string(9) "栏目二" ["subcat"]=> array(2) { [0]=> array(3) { ["id"]=> int(4) ["pid"]=> int(2) ["cat"]=> string(9) "栏目四" } [1]=> array(4) { ["id"]=> int(13) ["pid"]=> int(2) ["cat"]=> string(12) "栏目十三" ["subcat"]=> array(1) { [0]=> array(3) { ["id"]=> int(14) ["pid"]=> int(13) ["cat"]=> string(12) "栏目十四" } } } } } [2]=> array(4) { ["id"]=> int(10) ["pid"]=> int(0) ["cat"]=> string(9) "栏目十" ["subcat"]=> array(1) { [0]=> array(4) { ["id"]=> int(11) ["pid"]=> int(10) ["cat"]=> string(12) "栏目十一" ["subcat"]=> array(1) { [0]=> array(3) { ["id"]=> int(12) ["pid"]=> int(11) ["cat"]=> string(12) "栏目十二" } } } } } } ```