note 107095 deleted from function.sort by danbrown

From: Date: Fri, 06 Jan 2012 19:06:05 +0000
Subject: note 107095 deleted from function.sort by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-185395@lists.php.net to get a copy of this message
Note Submitter: graudonas at gmail dot com ---- Function order_array_num mentioned bellow has one mistake. When array is reassigned, we don't need to say indexes for a new array such as they were for an old array. It means that instead of $tmp2[$key] = $array[$key]; we could write just $tmp2[] = $array[$key];. Or the whole function could look like this: function order_array_num ($array, $key, $order = "ASC") { $tmp = array(); foreach($array as $akey => $array2) $tmp[$akey] = $array2[$key]; if ($order == "DESC") arsort($tmp,SORT_NUMERIC); else asort($tmp,SORT_NUMERIC); $tmp2 = array(); foreach($tmp as $key => $value) $tmp2[] = $array[$key]; return $tmp2; }

« previous php.notes (#185395) next »