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.

هل استفدت من هذا الجواب؟

 أطبع هذا المقال

اقرأ أيضا

subdomain and directory question

Posted by azn_romeo_4u, 03-27-2008, 01:02 AMHow do those websites do a website like this....

The Planet Monitoring System .... SSH critical status

Posted by xmlxp, 09-15-2007, 03:52 PMam recieving an email every hour from the Monitoring System...

Domain names diferent servers.

Posted by shakybaky, 06-26-2008, 02:34 PMhello i have two nix vps's One of the vps is setup and...

3-line PHP chat

Posted by Looie, 01-15-2008, 03:28 PMJust an idea I had http://www.ehwtf.com/stuffz/chat...

File Server Setup With Nginx...how do I choose the config for the server?

Posted by azn_romeo_4u, 04-22-2009, 02:03 PMSo I just want to use a server for file sharing, it...