note 74618 deleted from function.array-multisort by colder

From: Date: Fri, 20 Apr 2007 13:58:13 +0000
Subject: note 74618 deleted from function.array-multisort by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-125615@lists.php.net to get a copy of this message
Note Submitter: Bjørn Grathwohl ---- <?php function array_sort_by_key($array, $sort_key, $order = SORT_ASC) { if($order != SORT_ASC && $order != SORT_DESC) return false; $keys = array_keys($array); $place = array_search($sort_key, $keys); foreach($array as $key => $row) { $sortingParameter[$key] = $row[$sort_key]; if($place == 0) { $theRest[$key] = array_slice($row, 1, count($row)); } else if($place == count($row) + 1) { $theRest[$key] = array_slice($row, 0, count($row) - 1); } else { $left = array_slice($row, 0, $place); $right = array_slice($row, $place + 1, count($row) - $place); $theRest[$key] = array_merge($left, $right); } } array_multisort($sortingParameter, $order, $theRest, $array); return $array; } ?>

« previous php.notes (#125615) next »