note 113445 added to function.array-multisort

From: Date: Fri, 11 Oct 2013 15:25:03 +0000
Subject: note 113445 added to function.array-multisort
Groups: php.notes 
Request: Send a blank email to php-notes+get-196527@lists.php.net to get a copy of this message
When sorting an array of (complex) objects, this function can give you a "Fatal error: Nesting level too deep" since it directly compares elements in later arrays if the elements in earlier ones compare equal. This can be worked around with the Flag-Parameter: <?php $sortKeys = array_map($extractKey, $lotsOfComplexObjects); array_multisort($sortKeys, $lotsOfComplexObjects, SORT_ASC, SORT_NUMERIC); ?> I'm replacing an 'uasort()'-call which is significantly slower since it leads to a lot of calls to the comparison-function but most of the objects involved are recursive. If this 'trick' gives a wrong order, you need a better key. ---- Server IP: 69.147.83.199 Probable Submitter: 80.153.180.160 ---- Manual Page -- http://php.net/manual/en/function.array-multisort.php Edit -- https://master.php.net/note/edit/113445 Del: integrated -- https://master.php.net/note/delete/113445/integrated Del: useless -- https://master.php.net/note/delete/113445/useless Del: bad code -- https://master.php.net/note/delete/113445/bad+code Del: spam -- https://master.php.net/note/delete/113445/spam Del: non-english -- https://master.php.net/note/delete/113445/non-english Del: in docs -- https://master.php.net/note/delete/113445/in+docs Del: other reasons-- https://master.php.net/note/delete/113445 Reject -- https://master.php.net/note/reject/113445 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#196527) next »