note 59168 added to function.uksort

From: Date: Mon, 28 Nov 2005 11:57:54 +0000
Subject: note 59168 added to function.uksort
Groups: php.notes 
Request: Send a blank email to php-notes+get-99232@lists.php.net to get a copy of this message
As silly as it may seem, you may sometimes need a comparison function which leaves the array in the same order. It's not as trivial as returning 0 (zero) all the time, since for some reason it doesn't actually leave the values alone. Here's a simpler and faster version of the code presented by Ignatius Reilly in an earlier note, which can be used to infer original position based on the original array: function cmp($a, $b) { if ($a == $b) return 0; global $target_array_here; static $keys; if (!$keys) $keys = array_keys($target_array_here); $x = array_search($a, $keys); $y = array_search($b, $keys); return ($x < $y ? -1 : 1); } ---- Manual Page -- http://www.php.net/manual/en/function.uksort.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+59168 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59168&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59168&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59168&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59168&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59168&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59168&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59168&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+59168&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#99232) next »