學習PHP時,你可能會遇到PHP多維數組排序問題,這裡將介紹PHP多維數組排序問題的解決方法,在這裡拿出來和大家分享一下,希望對大家有幫助。
- functioncmp($a,$b){
- if($a[”nums”]==$b[”nums”]){
- return0;
- }
- return($a[”nums”]<$b[”nums”])?-1:1;
- }
- $arr=Array(
- 0=>Array(
- “username”=>owen,
- “nums”=>2,
- ),
- 1=>Array(
- “username”=>d5s,
- “nums”=>5,
- ),
- 2=>Array(
- “username”=>pt,
- “nums”=>3,
- ),
- );
- uasort($arr,“cmp”);
- echo‘<prestyleprestyle=”text-align:left”>’;
- print_r($arr);
- echo‘< SPAN>pre>’;
- ?>
- Array
- (
- [0]=>Array
- (
- [username]=>owen
- [nums]=>2
- )
- [2]=>Array
- (
- [username]=>pt
- [nums]=>3
- )
- [1]=>Array
- (
- [username]=>d5s
- [nums]=>5
- )
- )