note 112221 added to array.sorting

From: Date: Fri, 17 May 2013 20:28:37 +0000
Subject: note 112221 added to array.sorting
Groups: php.notes 
Request: Send a blank email to php-notes+get-194850@lists.php.net to get a copy of this message
While this may seem obvious, user-defined array sorting functions ( uksort(), uasort(), usort() ) will *not* be called if the array does not have *at least two values in it*. The following code: <?php function usortTest($a, $b) { var_dump($a); var_dump($b); return -1; } $test = array('val1'); usort($test, "usortTest"); $test2 = array('val2', 'val3'); usort($test2, "usortTest"); ?> Will output: string(4) "val3" string(4) "val2" The first array doesn't get sent to the function. Please, under no circumstance, place any logic that modifies values, or applies non-sorting business logic in these functions as they will not always be executed. ---- Server IP: 192.41.42.26 Probable Submitter: 70.62.71.144 ---- Manual Page -- http://php.net/manual/en/array.sorting.php Edit -- https://master.php.net/note/edit/112221 Del: integrated -- https://master.php.net/note/delete/112221/integrated Del: useless -- https://master.php.net/note/delete/112221/useless Del: bad code -- https://master.php.net/note/delete/112221/bad+code Del: spam -- https://master.php.net/note/delete/112221/spam Del: non-english -- https://master.php.net/note/delete/112221/non-english Del: in docs -- https://master.php.net/note/delete/112221/in+docs Del: other reasons-- https://master.php.net/note/delete/112221 Reject -- https://master.php.net/note/reject/112221 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#194850) next »