PHP custom two-dimensional array sorting

不言
Release: 2023-03-24 17:58:01
Original
1971 people have browsed it

The main content of this article is about PHP custom two-dimensional array sorting, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

function array_sort($arr,$keys,$type='asc'){ $keysvalue = $new_array = array(); foreach ($arr as $k=>$v){ $keysvalue[$k] = $v[$keys]; } if($type == 'asc'){ asort($keysvalue); }else{ arsort($keysvalue); } reset($keysvalue); echo "
"; print_r($keysvalue); foreach ($keysvalue as $k=>$v){ $new_array[$k] = $arr[$k]; } return $new_array; }
Copy after login

Copy after login
$array = array( array('name'=>'手机','brand'=>'诺基亚','price'=>1050), array('name'=>'笔记本电脑','brand'=>'lenovo','price'=>4300), array('name'=>'剃须刀','brand'=>'飞利浦','price'=>3100), array('name'=>'跑步机','brand'=>'三和松石','price'=>4900), array('name'=>'手表','brand'=>'卡西欧','price'=>960), array('name'=>'液晶电视','brand'=>'索尼','price'=>6299), array('name'=>'激光打印机','brand'=>'惠普','price'=>1200) ); $ShoppingList = array_sort($array,'price'); echo "
"; print_r($ShoppingList);
Copy after login

Related recommendations:

PHP two-dimensional array sorted by key value

php two-dimensional array deduplication method

PHP two-dimensional array Sort array_multisort




The above is the detailed content of PHP custom two-dimensional array sorting. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn