Question on array sorting in php

Posted by computerwiz3491, 01-17-2008, 05:10 PM
I have the following array that I printed using print_r I need to be able to sort it by [pubDate] in highest to lowest order. How would I do this? Thanx

Posted by Codebird, 01-17-2008, 06:35 PM
you can use your pubDate as Key and then ksort($item);

Posted by computerwiz3491, 01-17-2008, 09:33 PM
It's a multi-dimensional array which has to stay in the same format.

Posted by foobic, 01-17-2008, 09:54 PM
You still need to do as Hicham suggested: create an additional array keyed on pubDate containing the same objects. Ideally you do this at the same time as creating your original array; if not you'll have to iterate through the original, eg. using array_map.

Posted by bigfan, 01-17-2008, 10:19 PM
Use array_multisort():That should work on the array as shown. (Although I think there's more to it than what you posted. If so adjust the keys for the values of $val assigned to $tmp as needed.)

Posted by bigfan, 01-18-2008, 11:39 AM
Assume an XML document like this:Then this code:will give you this: Last edited by bigfan; 01-18-2008 at 11:53 AM.

Was dit antwoord nuttig?

 Print dit artikel

Lees ook

Can some explain this in a simple way?

Posted by subhash, 02-21-2011, 07:52 AMHello Guys, Can some body explain what exactly is...

SQL DB backup error !

Posted by htw_Mehdi, 09-14-2007, 09:28 PMhello, when i try to backup mysql database on the...

Linux: backup hard drive mounted to /backup

Posted by UberTricep, 11-10-2012, 07:49 AMI have a new dedicated server and I ordered a backup...

time overlap = total

Posted by ti_nhatrang, 02-07-2011, 10:21 AMHi guys, I got this table with call logs start and...

sshd has failed, please contact the sysadmin

Posted by X-x-X, 01-23-2007, 12:31 PMi have problem in SSH if i want to restart it its say :...