<?php
function array_natcase($key, $array, $ascdesc='asc')
{
$temp = array();
$final = array();
foreach($array as $id=>$value)
{
$temp[$id] = $value[$key];
}
natcasesort($temp);
foreach($temp as $id=>$value)
{
$final[$id] = $array[$id];
}
if($ascdesc{0} === 'd')
{
$final = array_reverse($final, true);
}
return $final;
}
?>
ÖRNEK
<?php
$array = array(
'a'=>array('x'=>10, 'other'=>'egh'),
'q'=>array('x'=>9, 'other'=>'blah'),
'7'=>array('x'=>1, 'other'=>'rawr'),
'6'=>array('x'=>22, 'other'=>'abcd'));
$array = array_natcase('x', $array);
//outputs the array in the following order
// 7, q, a, 6
?>
|