I've the following multidimensional array:
Array
(
[0] => Array
(
[codes] => Array
(
[2] => 01
[1] => 01
[0] => 02
)
[name] => Test
)
[1] => Array
(
[codes] => Array
(
[1] => 02
[0] => 03
)
[name] => Test
)
[2] => Array
(
[codes] => Array
(
[3] => 01
[2] => 01
[1] => 01
[0] => 02
)
[name] => Test
)
)
I need to sort the array by the codes
value, so in this example the expected array would be:
Array
(
[0] => Array
(
[codes] => Array
(
[3] => 01
[2] => 01
[1] => 01
[0] => 02
)
[name] => Test
)
[1] => Array
(
[codes] => Array
(
[2] => 01
[1] => 01
[0] => 02
)
[name] => Test
)
[2] => Array
(
[codes] => Array
(
[1] => 02
[0] => 03
)
[name] => Test
)
)
The solution I was thinking is to use the uasort function using strnatcasecmp as a callback, like this:
uasort($array, function($a, $b) {
return strnatcasecmp($a['codes'], $b['codes']);
});
But it won't work because codes
is an array. I don't know how to implement it in this case.
Any idea?