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.

¿Fue útil la respuesta?

 Imprimir éste Artículo

Leer también

changing register_globals from .htaccess will cause 500 Error when php run as CGI

Posted by mshannaq, 05-07-2007, 01:44 PMHello, Today I have a customer want to swich the...

How can I fix this?

Posted by TylerH, 09-18-2008, 06:06 AMFor some reason my sendmail is not working and I tired...

URL Rewrite

Posted by beachcompcom, 03-08-2010, 04:34 PMHi folks, I'm new to IIS7/Url rewrites. Im trying...

Cannot open database asp.net

Posted by Faiyaz, 09-22-2008, 03:02 PMCannot open database "DATABASENAME" requested by the login....

Seeking a new host

Posted by Bloory, 08-03-2002, 12:57 PMI'm looking for a host with a maximum cost of around £35...