Answer the question
In order to leave comments, you need to log in
PHP Nest associative arrays inside each other?
Hello everyone, I have an array
array(15) {
[0]=>
array(4) {
["DEPTH_LEVEL"]=>
string(1) "1"
["IS_PARENT"]=>
bool(true)
["NAME"]=>
string(10) "Обувь"
["LINK"]=>
string(15) "/catalog/shoes/"
}
[1]=>
array(4) {
["DEPTH_LEVEL"]=>
string(1) "2"
["IS_PARENT"]=>
bool(false)
["NAME"]=>
string(18) "Пантолеты"
["LINK"]=>
string(19) "/catalog/pantolety/"
}
[2]=>
array(4) {
["DEPTH_LEVEL"]=>
string(1) "2"
["IS_PARENT"]=>
bool(false)
["NAME"]=>
string(14) "Тапочки"
["LINK"]=>
string(18) "/catalog/slippers/"
}
[3]=>
array(4) {
["DEPTH_LEVEL"]=>
string(1) "2"
["IS_PARENT"]=>
bool(true)
["NAME"]=>
string(10) "Туфли"
["LINK"]=>
string(16) "/catalog/shoess/"
}
[4]=>
array(4) {
["DEPTH_LEVEL"]=>
string(1) "3"
["IS_PARENT"]=>
bool(false)
["NAME"]=>
string(26) " Туфли Женские"
["LINK"]=>
string(23) "/catalog/women-s-shoes/"
}
[5]=>
array(4) {
["DEPTH_LEVEL"]=>
string(1) "3"
["IS_PARENT"]=>
bool(false)
["NAME"]=>
string(25) "Туфли Мужские"
["LINK"]=>
string(20) "/catalog/shoes-mens/"
}
[6]=>
array(4) {
["DEPTH_LEVEL"]=>
string(1) "1"
["IS_PARENT"]=>
bool(false)
["NAME"]=>
string(12) "Платья"
["LINK"]=>
string(17) "/catalog/dresses/"
}
[7]=>
array(4) {
["DEPTH_LEVEL"]=>
string(1) "1"
["IS_PARENT"]=>
bool(false)
["NAME"]=>
string(10) "Штаны"
["LINK"]=>
string(15) "/catalog/pants/"
}
[8]=>
array(4) {
["DEPTH_LEVEL"]=>
string(1) "1"
["IS_PARENT"]=>
bool(false)
["NAME"]=>
string(23) "Нижнее белье"
["LINK"]=>
string(19) "/catalog/underwear/"
}
[9]=>
array(4) {
["DEPTH_LEVEL"]=>
string(1) "1"
["IS_PARENT"]=>
bool(false)
["NAME"]=>
string(16) "Футболки"
["LINK"]=>
string(18) "/catalog/t-shirts/"
}
[10]=>
array(4) {
["DEPTH_LEVEL"]=>
string(1) "1"
["IS_PARENT"]=>
bool(false)
["NAME"]=>
string(101) "Спортивная Одежда Спортивная Одежда Спортивная Одежда"
["LINK"]=>
string(20) "/catalog/sportswear/"
}
[11]=>
array(4) {
["DEPTH_LEVEL"]=>
string(1) "1"
["IS_PARENT"]=>
bool(true)
["NAME"]=>
string(20) "Аксессуары"
["LINK"]=>
string(21) "/catalog/accessories/"
}
[12]=>
array(4) {
["DEPTH_LEVEL"]=>
string(1) "2"
["IS_PARENT"]=>
bool(true)
["NAME"]=>
string(10) "Ремни"
["LINK"]=>
string(15) "/catalog/belts/"
}
[13]=>
array(4) {
["DEPTH_LEVEL"]=>
string(1) "3"
["IS_PARENT"]=>
bool(false)
["NAME"]=>
string(25) "Ремни Женские"
["LINK"]=>
string(23) "/catalog/women-s-belts/"
}
[14]=>
array(4) {
["DEPTH_LEVEL"]=>
string(1) "3"
["IS_PARENT"]=>
bool(false)
["NAME"]=>
string(25) "Ремни Мужские"
["LINK"]=>
string(21) "/catalog/men-s-belts/"
}
}
Answer the question
In order to leave comments, you need to log in
Trees are stored differently. Usually parent_id. Sometimes left-right (nested sets). Sometimes some other formats.
Manually bring your structure to the correct form.
Here is a description of the main ways to store trees: https://habrahabr.ru/post/46659/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question