0

How can I sort alphabetically this multidimensional-array, by the value of the "code" key?

Array
(
[0] => Array
    (
        [Products] => Array
            (
                [code] => LD
                [power] => 5
                [channels] => 2
            )
    )
[1] => Array
    (
        [Products] => Array
            (
                [code] => CAE
                [power] => 15
                [channels] => 1
            )
    )
[2] => Array
    (
        [Products] => Array
            (
                [code] => FC
                [power] => 12
                [channels] => 1
            )
    )

I have checked other post, but no one has an array like this.

EDIT: this is my attempt

function sortByCode($a, $b) {
    return strcmp($a['code'], $b['code']);
}

and then:

usort($myarray['Products'], 'sortByCode');

I know it's wrong, but I don't know how make it work!

Andrea
  • 1
  • 2

0 Answers0