gpt4 book ai didi

php - 如何将 MPTT 层次结构数据正确排序到多维数组中。

转载 作者:行者123 更新时间:2023-12-02 05:14:33 25 4
gpt4 key购买 nike

我正在尝试弄清楚如何编写返回多维数组的函数。我知道如何使用“category_parent”值编写函数。但我只是想编写一个函数,仅使用左右键即可创建多维数组。

array(71) {
[0]=>
array(9) {
["id"]=>
string(1) "1"
["category_name"]=>
string(6) "Rubros"
["category_parent"]=>
string(1) "0"
["category_slug"]=>
string(6) "rubros"
["category_image"]=>
NULL
["category_totals"]=>
NULL
["category_lft"]=>
string(1) "1"
["category_rgt"]=>
string(3) "142"
}
[1]=>
array(9) {
["id"]=>
string(4) "1000"
["category_name"]=>
string(12) "Restaurantes"
["category_parent"]=>
string(1) "1"
["category_slug"]=>
string(12) "restaurantes"
["category_image"]=>
string(16) "restaurantes.png"
["category_totals"]=>
string(1) "1"
["category_lft"]=>
string(1) "2"
["category_rgt"]=>
string(2) "13"
}
[2]=>
array(9) {
["id"]=>
string(1) "3"
["category_name"]=>
string(21) "Restaurantes de Campo"
["category_parent"]=>
string(4) "1000"
["category_slug"]=>
string(21) "restaurantes-de-campo"
["category_image"]=>
NULL
["category_totals"]=>
string(1) "1"
["category_lft"]=>
string(1) "3"
["category_rgt"]=>
string(1) "4"
}
[3]=>
array(9) {
["id"]=>
string(2) "37"
["category_name"]=>
string(25) "Restaurantes en la Ciudad"
["category_parent"]=>
string(4) "1000"
["category_slug"]=>
string(19) "restaurantes-ciudad"
["category_image"]=>
string(0) ""
["category_totals"]=>
string(1) "6"
["category_lft"]=>
string(1) "5"
["category_rgt"]=>
string(1) "6"
}
[4]=>
array(9) {
["id"]=>
string(2) "41"
["category_name"]=>
string(21) "Servicios de Catering"
["category_parent"]=>
string(4) "1000"
["category_slug"]=>
string(8) "catering"
["category_image"]=>
string(0) ""
["category_totals"]=>
string(1) "1"
["category_lft"]=>
string(1) "7"
["category_rgt"]=>
string(1) "8"
}
[5]=>
array(9) {
["id"]=>
string(2) "48"
["category_name"]=>
string(10) "Rotiserias"
["category_parent"]=>
string(4) "1000"
["category_slug"]=>
string(10) "rotiserias"
["category_image"]=>
string(0) ""
["category_totals"]=>
string(1) "1"
["category_lft"]=>
string(1) "9"
["category_rgt"]=>
string(2) "10"
}
[6]=>
array(9) {
["id"]=>
string(2) "62"
["category_name"]=>
string(10) "Pizzerías"
["category_parent"]=>
string(4) "1000"
["category_slug"]=>
string(9) "pizzerias"
["category_image"]=>
string(0) ""
["category_totals"]=>
string(1) "1"
["category_lft"]=>
string(2) "11"
["category_rgt"]=>
string(2) "12"
}
[7]=>
array(9) {
["id"]=>
string(1) "2"
["category_name"]=>
string(13) "Profesionales"
["category_parent"]=>
string(1) "1"
["category_slug"]=>
string(13) "profesionales"
["category_image"]=>
string(17) "profesionales.png"
["category_totals"]=>
string(1) "2"
["category_lft"]=>
string(2) "14"
["category_rgt"]=>
string(2) "35"
}
[8]=>
array(9) {
["id"]=>
string(2) "29"
["category_name"]=>
string(11) "Arquitectos"
["category_parent"]=>
string(1) "2"
["category_slug"]=>
string(11) "arquitectos"
["category_image"]=>
NULL
["category_totals"]=>
string(1) "0"
["category_lft"]=>
string(2) "15"
["category_rgt"]=>
string(2) "16"
}
[9]=>
array(9) {
["id"]=>
string(2) "30"
["category_name"]=>
string(8) "Abogados"
["category_parent"]=>
string(1) "2"
["category_slug"]=>
string(8) "abogados"
["category_image"]=>
NULL
["category_totals"]=>
string(1) "6"
["category_lft"]=>
string(2) "17"
["category_rgt"]=>
string(2) "18"
}
}

感谢任何帮助!

最佳答案

你这样做就像从文件中分离数据一样,就像这样 '["dimensionOne"]["dimensionTwo"]'

关于php - 如何将 MPTT 层次结构数据正确排序到多维数组中。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1940288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com