note 99719 added to function.array-multisort
| From: | RicardoSismeiro at osu1 dot php dot net | Date: | Wed, 01 Sep 2010 14:37:55 +0000 |
| Subject: | note 99719 added to function.array-multisort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172235@lists.php.net to get a copy of this message | ||
<?php
$t = array();
$t[] =
array('m'=>1,'t'=>'a','d'=>array('k','k','k'));
$t[] =
array('m'=>4,'t'=>'e','d'=>array('w','w','w'));
$t[] =
array('m'=>3,'t'=>'d','d'=>array('h','h','h'));
$t[] =
array('m'=>2,'t'=>'c','d'=>array('e','e','e'));
$t[] =
array('m'=>5,'t'=>'b','d'=>array('i','i','i'));
function sort_by($array,$field,$desc='desc'){
$index = array();
$result = array();
foreach($array as $k=>$row){ $index[] = $row[$field];}
if ('desc' == $desc){ arsort($index); } else { asort($index);}
foreach($index as $k=>$value){ $result[] = $array[$k]; unset($array[$k]); }
return $result;
}
$m1 = sort_by($t, 'm');
$m2 = sort_by($t, 't');
print_r($m1);
print_r($m2);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 109.71.42.6
----
Manual Page -- http://www.php.net/manual/en/function.array-multisort.php
Edit -- https://master.php.net/note/edit/99719
Del: integrated -- https://master.php.net/note/delete/99719/integrated
Del: useless -- https://master.php.net/note/delete/99719/useless
Del: bad code -- https://master.php.net/note/delete/99719/bad+code
Del: spam -- https://master.php.net/note/delete/99719/spam
Del: non-english -- https://master.php.net/note/delete/99719/non-english
Del: in docs -- https://master.php.net/note/delete/99719/in+docs
Del: other reasons-- https://master.php.net/note/delete/99719
Reject -- https://master.php.net/note/reject/99719
Search -- https://master.php.net/manage/user-notes.php