note 117659 added to function.usort

From: Date: Thu, 16 Jul 2015 23:13:30 +0000
Subject: note 117659 added to function.usort
Groups: php.notes 
Request: Send a blank email to php-notes+get-203119@lists.php.net to get a copy of this message
I see many people here (including the official examples) write their callbacks rather clumsily like this: <?php function($a, $b) { if ($a === $b) { return 0; } elseif ($a < $b) { return -1; } else { return 1; } } ?> Or if they are a bit more clever: <?php function($a, $b) { if ($a === $b) { return 0; } else { return $a < $b ? -1 : 1; } } ?> But this can by simplified further to: <?php function($a, $b) { return $a - $b; } ?> ---- Server IP: 72.55.140.6 Probable Submitter: 174.113.241.175 ---- Manual Page -- http://php.net/manual/en/function.usort.php Edit -- https://master.php.net/note/edit/117659 Del: integrated -- https://master.php.net/note/delete/117659/integrated Del: useless -- https://master.php.net/note/delete/117659/useless Del: bad code -- https://master.php.net/note/delete/117659/bad+code Del: spam -- https://master.php.net/note/delete/117659/spam Del: non-english -- https://master.php.net/note/delete/117659/non-english Del: in docs -- https://master.php.net/note/delete/117659/in+docs Del: other reasons-- https://master.php.net/note/delete/117659 Reject -- https://master.php.net/note/reject/117659 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#203119) next »