note 44163 added to function.array-multisort

From: Date: Fri, 16 Jul 2004 12:16:23 +0000
Subject: note 44163 added to function.array-multisort
Groups: php.notes 
Request: Send a blank email to php-notes+get-73380@lists.php.net to get a copy of this message
I made this little function for sorting small multi-dim arrays by a chosen column in multiple rows. Sorts numeric, ascending. <?php // $arr = array to sort. // $col = column to sort by. function incision_sort($arr, $col){ for($k = 0; $k < sizeof($arr)-1; $k++){ // $arr[$k+1] is possibly in the wrong place. Take it out. $t = $arr[$k+1]; $i = $k; // Push $arr[i] to the right until we find the right place for $t. while($i >= 0 && $arr[$i][$col] > $t[$col]){ $arr[$i+1] = $arr[$i]; $i--; } // Insert $t into the right place. $arr[$i+1] = $t; }// End sort return $arr; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.array-multisort.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44163 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44163&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44163&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#73380) next »