PHP sort an array by its subarray values
Well, PHP certainly has plenty of array sorting functions. But I can't
find one that would sort this array by "age" from highest to lowest.
$a = array(
[0] => array(
[name] => 'Don',
[age] => 12
),
[1] => array(
[name] => 'James',
[age] => 5
),
[2] => array(
[name] => 'Wurnstrum',
[age] => 8
)
);
Checked http://www.php.net/manual/en/ref.array.php. The closest I found
was asort(), but that seems to just sort within each person's subarray.
usort() also looks promising but doesn't seem to work for this case.
No comments:
Post a Comment