PHP / How to sort array by value of nested array

Array
(
    [javascript] => Array
        (
            [core] => Array
                (
                    [0] => Array
                        (
                            [file] => /path/to/file.js
                            [weight] => 0
                        )

                    [1] => Array
                        (
                            [file] => /path/to/file2.js
                            [weight] => 1
                        )

                )

        )

) 
 
For example, this needs to be sorted by 'weight' value. Such kind of tasks can be solved using closures:
usort($array['javascript']['core'], function($a, $b) { return $a['weight'] - $b['weight']; });
  

No comments:

Post a Comment