Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #11042
| Path | csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | "Peter H. Coffin" <hellsop@ninehells.com> |
| Newsgroups | comp.lang.php |
| Subject | Re: sort array of objects by muliple values |
| Date | Thu, 27 Jan 2011 14:46:21 -0600 |
| Organization | A noiseless patient Spider |
| Lines | 56 |
| Message-ID | <slrnik3mct.2mh.hellsop@nibelheim.ninehells.com> (permalink) |
| References | <b161047b-cf9d-4fb4-b8c0-9edcdf52a1b9@h16g2000yqh.googlegroups.com> <ihsfuu$eo6$1@news.eternal-september.org> <eb45b444-6ebe-4581-8b25-69f4c101e525@a4g2000yqo.googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| Injection-Info | mx01.eternal-september.org; posting-host="le/2G4+BNpieVhQI6uJ2Lw"; logging-data="3278"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qRmGC5xvHrBIsBD1fOW2K" |
| User-Agent | slrn/0.9.9p1 (OpenBSD) |
| Cancel-Lock | sha1:MJgF7GzVvEt1XJdpeIwdWWOgJ+g= |
| Xref | csiph.com comp.lang.php:11042 |
Show key headers only | View raw
On Thu, 27 Jan 2011 11:59:28 -0800 (PST), Max wrote:
> On Jan 27, 8:10?pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> On 1/27/2011 2:04 PM, Max wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> > 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'),
>> > ? ? ? ? ?);
>>
>> Use usort() with a static member function. ?See
>>
>> http://us2.php.net/manual/en/function.usort.php
>>
>> for an example.
>
> it sorts only by one field
If you sort a sorted array by another column, what do you think happens
to the records in identically-keyed records?
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting. [TOFU := text oben,
Q: What is the most annoying thing on usenet? followup unten]
Back to comp.lang.php | Previous | Next — Next in thread | Find similar | Unroll thread
Re: sort array of objects by muliple values "Peter H. Coffin" <hellsop@ninehells.com> - 2011-01-27 14:46 -0600 Re: sort array of objects by muliple values Denis McMahon <denis.m.f.mcmahon@googlemail.com> - 2011-01-27 21:31 +0000
csiph-web