note 109840 added to function.sort

From: Date: Sun, 26 Aug 2012 20:29:58 +0000
Subject: note 109840 added to function.sort
Groups: php.notes 
Request: Send a blank email to php-notes+get-190225@lists.php.net to get a copy of this message
I saw another user on here post a snippet for sorting multi-dimensional associative arrays by using a specified index WITHOUT losing the relationships. I took part of that code and added more to make a fully functional .... function. function mArray_sort(&$input_array,$key,$order='ASC') { function sorter($key,$order) { if($order == "ASC") { return function ($a, $b) use ($key) { return strcasecmp($a[$key], $b[$key]); }; } elseif($order == "DESC") { return function ($b, $a) use ($key) { return strcasecmp($a[$key], $b[$key]); }; } } usort($input_array, sorter($key,strtoupper($order))); } Hope it helps someone in the future. ---- Server IP: 69.147.83.197 Probable Submitter: 71.239.132.135 ---- Manual Page -- http://www.php.net/manual/en/function.sort.php Edit -- https://master.php.net/note/edit/109840 Del: integrated -- https://master.php.net/note/delete/109840/integrated Del: useless -- https://master.php.net/note/delete/109840/useless Del: bad code -- https://master.php.net/note/delete/109840/bad+code Del: spam -- https://master.php.net/note/delete/109840/spam Del: non-english -- https://master.php.net/note/delete/109840/non-english Del: in docs -- https://master.php.net/note/delete/109840/in+docs Del: other reasons-- https://master.php.net/note/delete/109840 Reject -- https://master.php.net/note/reject/109840 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#190225) next »