php – 如何将一维数组转换为二维数组
作者:互联网
我有以下数组,来自一个表单,具有如下多语言数据:
Array
(
[en_name] => ...........
[en_description] => ...........
[gr_name] => ...........
[gr_description] => ...........
)
如何将此数组转换为二维,如:
Array
(
[en] => Array
(
[name] => ...........
[description] => ...........
)
[gr] => Array
(
[name] => ...........
[description] => ...........
)
)
解决方法:
使用此代码:
$finalArr = array();
foreach($arr as $key => $val) {
$tok = explode('_', $key);
$finalArr[$tok[0]][$tok[1]] = $val;
}
标签:php,arrays,multilingual 来源: https://codeday.me/bug/20190825/1723796.html