note 37664 deleted from function.usort by cmb

From: Date: Wed, 22 Jun 2016 17:29:02 +0000
Subject: note 37664 deleted from function.usort by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-205788@lists.php.net to get a copy of this message
Note Submitter: kristen at ccshoreline dot org ---- I have a class with a bunch of functions that work with an SQL database. I am working with calendar dates that occur more than once (like once a week for 2 months), so I have to generate the date in php after the SQL. But I wanted to sort the events based on the date, so I tried using usort, but was unable to get it to work, because it didn't think that my sorting function was defined (even though it was in the same class). I have a separate class to store the data, that has a variable called Start which is a PHP date object. So here is how I got it to work. First I created a temporary function, that returned the value of a string comparison of the timestamps for the dates. Then I used that temporary function for the usort. Enjoy. <?php $tempfunction = create_function('$event1,$event2', 'return strcmp($event1->Start[0],$event2->Start[0]);'); usort($data,$tempfunction); ?>

« previous php.notes (#205788) next »