Home > Backend Development > PHP Tutorial > php如何根据数组中其中的一个值排序

php如何根据数组中其中的一个值排序

WBOY
Release: 2016-06-13 12:18:40
Original
1228 people have browsed it

php怎么根据数组中其中的一个值排序
$arr = array('a'=>1,'c'=>3,'b'=>2);
asort($arr);
这样的排序我已经知道了

但是 如果一个二维数组
$arr[] = array('name'=>'a','flag'=>1);
$arr[] = array('name'=>'b','flag'=>2);
$arr[] = array('name'=>'a','flag'=>1);
我只想根据 键flag为的值  进行排序 
期望的效果为:
$arr[] = array('name'=>'a','flag'=>1);
$arr[] = array('name'=>'a','flag'=>1);
$arr[] = array('name'=>'b','flag'=>2);
希望大家帮帮忙
------解决思路----------------------

$arr[] = array('name'=>'a','flag'=>1);<br />$arr[] = array('name'=>'b','flag'=>2);<br />$arr[] = array('name'=>'a','flag'=>1);<br />$flag=array();<br />foreach($arr as $arr2){<br />	$flag[]=$arr2["flag"];<br />	}<br />array_multisort($flag, SORT_ASC, $arr);<br />print_r($arr);
Copy after login

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template