13,"name"=>"kitty"),array("ID"=>22,"name"=>"sony"),array("ID"=&g"/> 13,"name"=>"kitty"),array("ID"=>22,"name"=>"sony"),array("ID"=&g">

首頁 >後端開發 >php教程 > php二维数组排序,该怎么处理

php二维数组排序,该怎么处理

WBOY
WBOY原創
2016-06-13 13:30:01814瀏覽

php二维数组排序
$ary=array(array("ID"=>13,"name"=>"kitty"),array("ID"=>22,"name"=>"sony"),array("ID"=>17,"name"=>"picker"));
我想对其按照ID升序调整一维数组的顺序,结果为
array(array("ID"=>13,"name"=>"kitty"),array("ID"=>17,"name"=>"picker"),array("ID"=>22,"name"=>"sony"));
应该怎么写?

------解决方案--------------------
前两天才有人问过...

PHP code

$ary=array(array("ID"=>13,"name"=>"kitty"),array("ID"=>22,"name"=>"sony"),array("ID"=>17,"name"=>"picker"));
foreach ($ary as $key => $value) {
    $Id[$key] =$value['ID'];
    $Name[$key] = $value['name'];
}
array_multisort($Id, SORT_ASC,$ary);

print_r($ary); <div class="clear">
                 
              
              
        
            </div>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn