note 93473 added to function.sort

From: Date: Fri, 11 Sep 2009 13:29:12 +0000
Subject: note 93473 added to function.sort
Groups: php.notes 
Request: Send a blank email to php-notes+get-160453@lists.php.net to get a copy of this message
Here is a function to sort an array by the key of his sub-array with keep key in top level. function sksort(&$array, $subkey="id", $sort_descending=false, $keep_keys_in_sub = false) { $temp_array = $array; foreach ($temp_array as $key => &$value) { $sort = array(); foreach ($value as $index => $val) { $sort[$index] = $val[$subkey]; } asort($sort); $keys = array_keys($sort); $newValue = array(); foreach ($keys as $index) { if($keep_keys_in_sub) $newValue[$index] = $value[$index]; else $newValue[] = $value[$index]; } if($sort_descending) $value = array_reverse($newValue, $keep_keys_in_sub); else $value = $newValue; } $array = $temp_array; } ---- Server IP: 147.32.160.17 Probable Submitter: 89.29.90.77 ---- Manual Page -- http://www.php.net/manual/en/function.sort.php Edit -- https://master.php.net/note/edit/93473 Del: integrated -- https://master.php.net/note/delete/93473/integrated Del: useless -- https://master.php.net/note/delete/93473/useless Del: bad code -- https://master.php.net/note/delete/93473/bad+code Del: spam -- https://master.php.net/note/delete/93473/spam Del: non-english -- https://master.php.net/note/delete/93473/non-english Del: in docs -- https://master.php.net/note/delete/93473/in+docs Del: other reasons-- https://master.php.net/note/delete/93473 Reject -- https://master.php.net/note/reject/93473 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160453) next »