note 29746 added to function.array-multisort
| From: | (www.ichier.de) | Date: | Mon, 24 Feb 2003 01:42:56 +0000 |
| Subject: | note 29746 added to function.array-multisort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44414@lists.php.net to get a copy of this message | ||
heres my function to sort multidimensional arrays by column - needed to code this, cause i
didn't got tfrasers to work and couldn't use tnguyens, i think it's usefull,
didn't find one on the net
in my case the array has it's index as first dimension (i like that for using foreach later):
$array[0]['name'] = "Niko";
$array[0]['age'] = 24;
$array[1]['name'] = "Dennis";
$array[1]['age'] = 34;
the fuction:
function array_csort($marray, $column) { //coded by Ichier2003
foreach ($marray as $row) {
$sortarr[] = $row[$column];
}
array_multisort($sortarr, $marray);
return $marray;
}
just use it like that:
$array = array_csort($array,"age");
say it's tfrasers function, but this one works...
--
http://www.php.net/manual/en/function.array-multisort.php
http://master.php.net/manage/user-notes.php?action=edit+29746
http://master.php.net/manage/user-notes.php?action=delete+29746
http://master.php.net/manage/user-notes.php?action=reject+29746