Fund few functions to sort array but none of them can sort them if they are stdClass Object or ad least I could not find the right one
I need to sort this array by ordering value
[data] => Array
(
[0] => stdClass Object
(
[id] => 12
[name] => Title1
[ordering] => 1
)
[1] => stdClass Object
(
[id] => 14
[name] => Title2
[ordering] => 3
)
[2] => stdClass Object
(
[id] => 18
[name] => Title4
[ordering] => 2
)
[3] => stdClass Object
(
[id] => 22
[name] => Title5
[ordering] => 4
)
)
any help is appreciated. Thank you!
Define a custom sorting function based on
orderingfield of your objects, then pass it in with usort.docs for usort
Note that you don’t need to reassign
$input = usort(...)as the array is referenced insideusort