时间:2021-07-01 10:21:17 帮助过:50人阅读
array (size=6)
0 => string 'id' (length=2)
1 => string 'name' (length=4)
2 => string 'identityId' (length=10)
3 => string 'phone' (length=5)
4 => string 'email' (length=5)
5 => string 'schoolId' (length=8)
array (size=6)
'id' => string '唯一标识' (length=12)
'identityId' => string '身份证' (length=9)
'phone' => string '手机号' (length=9)
'email' => string '邮箱' (length=6)
'name' => string '姓名' (length=6)
'schoolId' => string '学校' (length=6)
如何让第二个数组按第一个数组的键值排序,即第二个数组变成id,name,identityId····
使用系统函数,谢谢诸位
有如下两个数组:
array (size=6)
0 => string 'id' (length=2)
1 => string 'name' (length=4)
2 => string 'identityId' (length=10)
3 => string 'phone' (length=5)
4 => string 'email' (length=5)
5 => string 'schoolId' (length=8)
array (size=6)
'id' => string '唯一标识' (length=12)
'identityId' => string '身份证' (length=9)
'phone' => string '手机号' (length=9)
'email' => string '邮箱' (length=6)
'name' => string '姓名' (length=6)
'schoolId' => string '学校' (length=6)
如何让第二个数组按第一个数组的键值排序,即第二个数组变成id,name,identityId····
使用系统函数,谢谢诸位
'唯一标识',
'identityId' => '身份证',
'phone' => '手机号',
'email' => '邮箱',
'name' => '姓名',
'schoolId' => '学校'
];
var_dump(array_merge(array_flip($a), $b));
使用系统函数 array_muiltsort
$arr1 = array(
'id',
'name',
'identityId',
'phone',
'email',
'schoolId'
);
$arr2 = array(
'id' => '唯一标识',
'identityId' => '身份证',
'phone' => '手机号',
'email' => '邮箱',
'name' => '姓名',
'schoolId' => '学校',
);
array_multisort($arr1,SORT_DESC,$arr2);
print_r($arr2);
//
结果为:
Array
(
[schoolId] => 学校
[email] => 邮箱
[identityId] => 身份证
[phone] => 手机号
[id] => 唯一标识
[name] => 姓名
)
$a = ['id','name','identityId','phone','email','schoolid'];
$b = ......;
foreach($a as $v){
$c[$v] = $b[$v];
}
$c即为你想要的数组;
$c = array();
foreach ($a as $value) $c[$value] = $b[$value];
print_r($c);