note 80276 added to function.sort

From: Date: Mon, 07 Jan 2008 20:25:48 +0000
Subject: note 80276 added to function.sort
Groups: php.notes 
Request: Send a blank email to php-notes+get-134931@lists.php.net to get a copy of this message
Update to the msort code posted by: alishahnovin I had a problem with the msort function not being case sensitive. All capital letters A-Z would list in order then all lowercase letters would follow. the line: if ($item[$id]<$array[$lowest_id][$id]) { was changed to: if (strtolower($item[$id]) < strtolower($array[$lowest_id][$id])) { <?php function msort($array, $id="id", $sort_ascending=true) { $temp_array = array(); while(count($array)>0) { $lowest_id = 0; $index=0; foreach ($array as $item) { if (isset($item[$id])) { if ($array[$lowest_id][$id]) { if (strtolower($item[$id]) < strtolower($array[$lowest_id][$id])) { $lowest_id = $index; } } } $index++; } $temp_array[] = $array[$lowest_id]; $array = array_merge(array_slice($array, 0,$lowest_id), array_slice($array, $lowest_id+1)); } if ($sort_ascending) { return $temp_array; } else { return array_reverse($temp_array); } } ?> ---- Server IP: 209.41.74.194 Probable Submitter: 66.202.7.251 ---- Manual Page -- http://www.php.net/manual/en/function.sort.php Edit -- https://master.php.net/note/edit/80276 Del: integrated -- https://master.php.net/note/delete/80276/integrated Del: useless -- https://master.php.net/note/delete/80276/useless Del: bad code -- https://master.php.net/note/delete/80276/bad+code Del: spam -- https://master.php.net/note/delete/80276/spam Del: non-english -- https://master.php.net/note/delete/80276/non-english Del: in docs -- https://master.php.net/note/delete/80276/in+docs Del: other reasons-- https://master.php.net/note/delete/80276 Reject -- https://master.php.net/note/reject/80276 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#134931) next »