Answer the question
In order to leave comments, you need to log in
How to sort an array using usort() in PHP?
Good evening.
There is an array:
[0] => Array
(
[code] => CAS
[name] => Корпуса
[code_parent] => 171
)
[1] => Array
(
[code] => MIN
[name] => Майнинг
[code_parent] => 171
)
[2] => Array
(
[code] => DVD
[name] => Оптические приводы
[code_parent] => 171
)
[3] => Array
(
[code] => VGP
[name] => Видеокарты
[code_parent] => 171
)
[4] => Array
(
[code] => BAC
[name] => Фен-Щётки
[code_parent] => 1434
)
[5] => Array
(
[code] => EPI
[name] => Эпиляторы
[code_parent] => 1434
)
[6] => Array
(
[code] => HCL
[name] => Машинки для стрижки
[code_parent] => 1434
)
[7] => Array
(
[code] => HDR
[name] => Фены
[code_parent] => 1434
)
[8] => Array
(
[code] => BSC
[name] => Напольные весы
[code_parent] => 1434
)
[9] => Array
(
[code] => SHR
[name] => Бритвы
[code_parent] => 1434
)
[10] => Array
(
[code] => 1434
[name] => Красота и здоровье
)
[11] => Array
(
[code] => 171
[name] => Комплектующие
)
[0] => Array
(
[code] => 1434
[name] => Красота и здоровье
)
[1] => Array
(
[code] => BAC
[name] => Фен-Щётки
[code_parent] => 1434
)
[2] => Array
(
[code] => EPI
[name] => Эпиляторы
[code_parent] => 1434
)
[3] => Array
(
[code] => HCL
[name] => Машинки для стрижки
[code_parent] => 1434
)
[4] => Array
(
[code] => HDR
[name] => Фены
[code_parent] => 1434
)
[5] => Array
(
[code] => BSC
[name] => Напольные весы
[code_parent] => 1434
)
[6] => Array
(
[code] => SHR
[name] => Бритвы
[code_parent] => 1434
)
[7] => Array
(
[code] => 171
[name] => Комплектующие
)
[8] => Array
(
[code] => CAS
[name] => Корпуса
[code_parent] => 171
)
[9] => Array
(
[code] => MIN
[name] => Майнинг
[code_parent] => 171
)
[10] => Array
(
[code] => DVD
[name] => Оптические приводы
[code_parent] => 171
)
[11] => Array
(
[code] => VGP
[name] => Видеокарты
[code_parent] => 171
)
Answer the question
In order to leave comments, you need to log in
This issue can also be considered closed. He got the solution here .
You can’t sort it like that, you need to group it into hierarchical subarrays, if more than one level, then generally using recursion.
You do not have sorting, but it is not clear what happens randomly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question