php array_combine 把array的默认键改成指定的字符串

array(2) {
[0] => array(6) {
[0] => string(1) "1"
[1] => string(10) "1470650276"
[2] => string(12) "测试人员"
[3] => string(9) "vpn出售"
[4] => string(20) "出售10个包月VPN"
[5] => string(6) "100000"
}
[1] => array(6) {
[0] => string(1) "2"
[1] => string(10) "1470650739"
[2] => string(12) "测试人员"
[3] => string(9) "服务器"
[4] => string(28) "双核CPU2G内存40SDD硬盘"
[5] => string(5) "15000"
}
}

改成

array(2) {
[0] => array(6) {
["record_id"] => string(1) "1"
["record_create_time"] => string(10) "1470650276"
["record_create_people"] => string(12) "测试人员"
["record_name"] => string(9) "vpn出售"
["record_comment"] => string(20) "出售10个包月VPN"
["record_money"] => string(6) "100000"
}
[1] => array(6) {
["record_id"] => string(1) "2"
["record_create_time"] => string(10) "1470650739"
["record_create_people"] => string(12) "测试人员"
["record_name"] => string(9) "服务器"
["record_comment"] => string(28) "双核CPU2G内存40SDD硬盘"
["record_money"] => string(5) "15000"
}
}

array_combine() 函数通过合并两个数组来创建一个新数组,其中的一个数组是键名,另一个数组的值为键值。

注释:键名数组和键值数组的元素个数必须相同!

如果其中一个数组为空,或者两个数组的元素个数不同,则该函数返回 false。

$key = array('a','b','c','d');
$array1 =array('0' => array('0'=>'first','1'=>'two','2'=>'hp','3'=>'aaa'),
'1' => array('0'=>'first','1'=>'two','2'=>'hp','3'=>'aaa'));
foreach($array1 as $kay=>$val ){
$array1[$kay] = array_combine($key,$val); }
var_dump($array1);
上一篇:less学习


下一篇:photoshop使用滤镜制作动态水波效果