note 29746 deleted from function.array-multisort by irchtml
| From: | irchtml@php.net | Date: | Wed, 25 Feb 2004 20:30:31 +0000 |
| Subject: | note 29746 deleted from function.array-multisort by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65757@lists.php.net to get a copy of this message | ||
Note Submitter: Ichier (www.ichier.de)
----
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...