News Feed
Sections




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

PHPEasy.co.uk:
Sorting array data using SplMaxHeap
July 18, 2012 @ 08:17:25

On PHPEasy.co.uk today there's a new tutorial posted showing you how to sort using the SplMaxHeap functionality provided by the Standard PHP Library.

The SplMaxHeap class basically stores numbers in any order, and then returns them in descending order. In order to make this class useful for other data types other than numbers I have extend the SplMaxHeap class to compare dates and strings. SplMaxHeap extends SplHeap and implements the abstract class SplHeap::compare. Our extention of SplMaxHeap is therefore expected to implement the compare method.

Code examples are given showing sorting by things like "last name" and "date of birth" (using strtotime). There's also an example of its use in sorting values from an array and outputted in a loop. You can find out more about this functionality in the PHP manual.

0 comments voice your opinion now!
sort data splmaxheap compare function tutorial


blog comments powered by Disqus

Similar Posts

Brian Moon's Blog: PHP and Memcached: The state of things

NetTuts.com: Refactoring Legacy Code: Part 1 - The Golden Master

DevGuide.net: Dynamic Bitmap Graphics with PHP and GD

Eirik Hoem's Blog: Dying with grace - PHP's register_shutdown_function

php|architect: Transactional Emails for Fun and Profit


Community Events





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


composer conference laravel series introduction opinion framework voicesoftheelephpant library language security interview community symfony tool version list artisanfiles release podcast

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