News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Felix Geisendorfer's Blog:
Sorting Challenge
October 26, 2007 @ 08:42:00

Felix Geisendorfer has a quick little sorting example posted today showing on way to sort a multi-dimensional array.

Quick challenge, lets say you have an array and you want to iterate through your products by [the key of each subarray in $products] Product.ordering ASC. Whats the fastest way to do this?

His solution involves using an array_flip call on the extracted information (using Set::extract), ordering it with ksort and pushing the values back into the $product array in the right order.

Check out the comments for more examples including ones that make use of array_multisort.

0 comments voice your opinion now!
sort challenge arraymultisort arrayflip foreach array sort challenge arraymultisort arrayflip foreach array


blog comments powered by Disqus

Similar Posts

PHPBuilder.com: Introduction to Arrays and Hashes in PHP - The ABC's of PHP Part 7

Brandon Savage's Blog: Five Cool PHP Array Functions

Nikita Popov's Blog: Understanding PHP's internal array implementation (Part 4)

Stijn Leenknegt's Blog: [PHP6] function-return-array idea!

QaFoo.com Blog: Struct classes in PHP


Community Events





Don't see your event here?
Let us know!


community development podcast conference laravel language threedevsandamaybe symfony series introduction tips code interview framework deployment list api bugfix release zendserver

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework