实例如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
$arr = array( 0=>array('key1'=>'value1' , 'key2'=>'value2'), 1=>array('key1'=>'value1' , 'key2'=>'value3'), 2=>array('key1'=>'value2' , 'key2'=>'value4'), 999=>array('key1'=>'value2' , 'key2'=>'value5') ); $result = array(); < span style = "color:#FF0000;" >foreach ($arr as $data) { isset($result[$data['key1']]) || $result[$data['key1']] = array(); $result[$data['key1']][] = $data['key2']; }</ span > ksort($cityAr, SORT_NATURAL);//这个是键值按字母先后顺序排列 print_r($result); //输出如下 Array ( [value1] => Array ( [0] => value2 [1] => value3 ) [value2] => Array ( [0] => value4 [1] => value5 ) ) |
原文链接:http://blog.csdn.net/jiangnanqbey/article/details/78863688
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容