note 104780 deleted from function.sort by danbrown

From: Date: Thu, 07 Jul 2011 13:26:00 +0000
Subject: note 104780 deleted from function.sort by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181316@lists.php.net to get a copy of this message
Note Submitter: k4m ---- little change for nice function from Dollar Hauler Admin. With this change you dont have to add extra keys just put an array or single string. example: $arr = multisort($some_array, 'name',array('id','name','category')); or $arr = multisort($some_array, 'name', 'id'); //if you need only name and id CODE: function multisort($array, $sort_by, $keys) { foreach ($array as $pos => $val) $tmp_array[$pos] = $val[$sort_by]; asort($tmp_array); foreach ($tmp_array as $pos => $val) { $return_array[$pos][$sort_by] = $array[$pos][$sort_by]; if(is_array($keys)) { foreach($keys as $k) $return_array[$pos][$k] = $array[$pos][$k]; } else $return_array[$pos][$keys] = $array[$pos][$keys]; } return $return_array; }

« previous php.notes (#181316) next »