把array的默认键改成指定的字符串
程序员文章站
2022-04-29 11:11:18
...
dump($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"
}
}
回复内容:
dump($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"
}
}
$keys = array('record_id', 'record_create_time', 'record_create_people', 'record_name', 'record_comment', 'record_money');
foreach ($array as $i=>$vals) {
$array[$i] = array_combine($keys, $vals);
}
var_dump($array);
可以看一下手册中数组操作的函数
上一篇: win10电脑无法打开wlan怎么解决
下一篇: wxPython窗口中文乱码解决方法
推荐阅读
-
解析array splice的移除数组中指定键的值,返回一个新的数组
-
php把字符串指定字符分割成数组的方法
-
解析array splice的移除数组中指定键的值,返回一个新的数组
-
解析array splice的移除数组中指定键的值,返回一个新的数组
-
怎么把未知长度的字符串从末尾截掉指定的字串呢
-
array_file_keys:使用指定的键和值填充数组
-
解析array splice的移除数组中指定键的值,返回一个新的数组_PHP教程
-
array_file_keys:使用指定的键和值填充数组
-
解析array splice的移除数组中指定键的值,返回一个新的数组_PHP
-
怎么把未知长度的字符串从末尾截掉指定的字串呢