Jump to content

Sorting three-dimensional associative arrays


SamCritch

Recommended Posts

Hi,

 

I want to sort a three-dimensional associative array containing some people's ages by age (so the sort would be numeric, rising). I've managed to work out how to use uasort() to do this with a two-dimensional associative array, but I can't seem to do this with a three-dimensional associative array.

 

Here's the array I have:

 

$demoarray = Array (
    'males' => Array (
        'george1' => Array ( 'name' => George, 'age' => 32 ),
    ),
    'females' => Array (
        'george1' => Array ( 'name' => Georgia, 'age' => 16 ),
        'george2' => Array ( 'name' => Georgette, 'age' => 54 ),
        'george3' => Array ( 'name' => Georgina, 'age' => 27 ),
    ),
) ;

 

How can I sort this so it comes back in ascending order of age across both males and females? Any ideas? Or am I misunderstanding the function?

 

Thanks in advance,

 

Sam

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.