Sorting a multi-dimensional array by element

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Sorting a multi-dimensional array by element

Post by malcolmboston »

example

Code: Select all

Array
(
    ї1] => Array
        (
            їid] => 1
            їname] => John
        )
    ї2] => Array
        (
            їid] => 2
            їname] => Roger
        )
    ї3] => Array
        (
            їid] => 3
            їname] => Adam
        )

)
short & sweet

how would you resort the array by name?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

usort()

You'll need to write a custom function to compare the elements. The PHP manual page on it is pretty easy to follow.
Post Reply