怎么对多维数组的键名进行排序
程序员文章站
2022-04-09 14:34:45
...
如何对多维数组的键名进行排序
比如
$families = array
(
"Griffin"=>array
(
"Peter"=>50
),
"Brown"=>array
(
"Cleveland"=>30
)
);
正序排,排完序后的键名和对应的键值不变,形如下面的形式:
$families = array
(
"Brown"=>array
(
"Cleveland"=>30
),
"Griffin"=>array
(
"Peter"=>50
)
);
------解决方案--------------------
比如
$families = array
(
"Griffin"=>array
(
"Peter"=>50
),
"Brown"=>array
(
"Cleveland"=>30
)
);
正序排,排完序后的键名和对应的键值不变,形如下面的形式:
$families = array
(
"Brown"=>array
(
"Cleveland"=>30
),
"Griffin"=>array
(
"Peter"=>50
)
);
------解决方案--------------------
- PHP code
foreach($families as $v) foreach($v as $vl) $p[]=$vl; array_multisort($p,SORT_ASC,$families); print_r($families);相关文章
相关视频
上一篇: 如何给phpadmin一个保护_PHP
下一篇: Webpack如何延迟储存缓存