FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » sort array of objects by muliple values
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
sort array of objects by muliple values [message #172015] Thu, 27 January 2011 19:04 Go to previous message
Max is currently offline  Max
Messages: 4
Registered: January 2011
Karma:
Junior Member
Is there a simple way to sort $array below like SQL it does? I.e.
ORDER BY birthday ASC, name ASC
Output would be Kevin, Michael, Alice

Thanks!

<?php
class User {
private $firstname;
private $surname;
private $birthday;

function __construct($firstname, $surname, $birthday) {
$this->firstname = $name;
$this->surname = $surname;
$this->birthday = $birthday;
}
function __get($n) {
return $this->$n;
}
}


$array = array (
new User('Alice', 'Smith', '1960-01-01'),
new User('Michael', 'Jordan', '1950-01-01'),
new User('Kevin', 'Dilan', '1950-01-01'),
);
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: SNMPv3 for PHP?
Next Topic: Using server to list CSS page list in menu
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 13:31:02 GMT 2024

Total time taken to generate the page: 0.04910 seconds