note 94663 deleted from function.sort by cmb

From: Date: Sun, 27 Oct 2019 08:35:55 +0000
Subject: note 94663 deleted from function.sort by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212790@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- [EDIT BY danbrown AT php DOT net: The code provided by this anonymous author contains bugfixes for and additions to code originally donated by "toenie" on 07-NOV-09. The original author included the following note: "If you want to sort while using an 2 dimensional array, you can use this script I just wrote for myself. I thought it could be helpful for other people too."] I also added the ability to sort in ascending and descending order. $order = "ASC" will sort the array in ascending order $order = "DESC" will sort the array in descending order Here is the code: <?php 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[$key] = $array[$key]; } return $tmp2; } ?>

« previous php.notes (#212790) next »