usort
How do I sort a PHP array by an element nested inside? [duplicate]
You can use usort as: function cmp($a, $b) { return $a[‘weight’] – $b[‘weight’]; } usort($arr,”cmp”);
usort(): Array was modified by the user comparison function
There is a PHP bug that can cause this warning, even if you don’t change the array. Short version, if any PHP debug functions examine the sort array, they will change the reference count and trick usort() into thinking you’ve changed the data. So you will get that warning by doing any of the following … Read more
Pass extra parameters to usort callback [duplicate]
I think this question deserves an update. I know the original question was for PHP version 5.2, but I came here looking for a solution and found one for newer versions of PHP and thought this might be useful for other people as well. For PHP 5.3 and up, you can use the ‘use‘ keyword … Read more