note 93106 deleted from function.usort by danbrown

From: Date: Tue, 03 Nov 2009 15:50:07 +0000
Subject: note 93106 deleted from function.usort by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162360@lists.php.net to get a copy of this message
Note Submitter: Will Shaver ---- With php 5.3.0 sorting by properties of an object becomes MUCH simpler. <?php function osort(&$array, $prop) { usort($array, function($a, $b) use ($prop) { return $a->$prop > $b->$prop ? 1 : -1; }); } ?> Note that this uses anonymous functions / closures. Might find reviewing the php docs on that useful. Look below for examples for previous version of php.

« previous php.notes (#162360) next »