note 93302 deleted from function.usort by thiago
| From: | thiago@php.net | Date: | Wed, 02 Sep 2009 13:42:59 +0000 |
| Subject: | note 93302 deleted from function.usort by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-160157@lists.php.net to get a copy of this message | ||
Note Submitter: sf dot ken dot online+php dot net at gmail dot com
----
http://t3.dotgnu.info/blog/php/schwartzian-transform.html
suggests an interesting, simple approach to stable sorting:
function dec(&$v, $k) { $v = array($v, $k);}
function undec(&$v, $k) { $v = $v[0]; }
array_walk($a, 'dec'); // decorate
sort($a); // sort
array_walk($a, 'undec'); // undecorate
(see link for explanation)