note 103047 added to function.array-multisort

From: Date: Tue, 22 Mar 2011 14:42:58 +0000
Subject: note 103047 added to function.array-multisort
Groups: php.notes 
Request: Send a blank email to php-notes+get-178098@lists.php.net to get a copy of this message
I had a problem with sorting SimpleXMLElement list. I found a nice short solution. I have an array of ticket objects: $ticketList = $xml->Tickets; // Sort by ValidOnDate $tickets = array(); $valid = array(); foreach ($ticketList as $row) { $tickets[] = $row; $valid[] = DateHandler::parseDate($row->ValidOnDate); } array_multisort($valid, SORT_DESC, $tickets); Just make an array of object items you want to sort by and a new array for the same objects which will be reordered like the first array. Ps: my own parseDate(date) returns unix timestamp for different date formats. ---- Server IP: 69.147.83.197 Probable Submitter: 195.50.207.6 ---- Manual Page -- http://www.php.net/manual/en/function.array-multisort.php Edit -- https://master.php.net/note/edit/103047 Del: integrated -- https://master.php.net/note/delete/103047/integrated Del: useless -- https://master.php.net/note/delete/103047/useless Del: bad code -- https://master.php.net/note/delete/103047/bad+code Del: spam -- https://master.php.net/note/delete/103047/spam Del: non-english -- https://master.php.net/note/delete/103047/non-english Del: in docs -- https://master.php.net/note/delete/103047/in+docs Del: other reasons-- https://master.php.net/note/delete/103047 Reject -- https://master.php.net/note/reject/103047 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178098) next »