1

I think I should be using usort but I have no idea how to get that working.

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

I would like to sort the index of core by the weight value, other files and weights will be added and sorted after also.

1 Answer 1

5
usort($array['javascript']['core'], function($a, $b) { return $a['weight'] - $b['weight']; }); 
Sign up to request clarification or add additional context in comments.

3 Comments

i needed to create an actual function instead of how you did it about but it worked perfectly, mind explaining what it is doing?
@user Yeah, sorry. The closure only works in PHP 5.3. Best thing to do is read the usort manual page. It has a pretty good definition of how the comparison function is used.
Had to change this to $a->weight - $b->weight because I am using an object, but this is perfect, thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.