php怎么遍历数组替换数组中的元素的值
时间:2021-07-15
来源:互联网
标签:
今天PHP爱好者给大家带来php遍历数组替换数组中元素值的方法:首先创建一个PHP示例文件;然后定义数组;最后通过“foreach($pid_arr_t as $key=>$value){...}”循环遍历并替换数组中元素的值即可。希望对大家有所帮助。

本文操作环境:windows7系统、PHP7.1版,DELL G3电脑
php怎么遍历数组替换数组中的元素的值?
php 修改数据中某个元素值,其它元素值不变。
循环数组
array(8) {
[0] => array(10) {
["opid"] => int(0)
["pid"] => int(11)
["price"] => string(4) "0.10"
["controller"] => string(4) "Live"
["type_mold"] => int(1)
["img"] => string(0) ""
["description"] => string(4) "1212"
["title"] => string(12) "测试回放"
["user_id"] => int(51)
["limit"] => string(19) "2020-01-25 15:03:14"
}
[1] => array(10) {
["opid"] => int(0)
["pid"] => int(10)
["price"] => string(4) "0.10"
["controller"] => string(4) "Live"
["type_mold"] => int(1)
["img"] => string(0) ""
["description"] => string(2) "12"
["title"] => string(12) "线上测试"
["user_id"] => int(51)
["limit"] => string(19) "2019-10-17 15:03:14"
}
[2] => array(10) {
["opid"] => int(0)
["pid"] => int(3)
["price"] => string(4) "1.00"
["controller"] => string(4) "Live"
["type_mold"] => int(1)
["img"] => string(0) ""
["description"] => string(4) "1212"
["title"] => string(21) "测试保长时直播"
["user_id"] => int(51)
["limit"] => string(19) "2019-10-17 15:03:14"
}
[3] => array(10) {
["opid"] => int(0)
["pid"] => int(2)
["price"] => string(4) "0.10"
["controller"] => string(5) "Video"
["type_mold"] => int(2)
["img"] => string(0) ""
["description"] => string(130) "最近长安刚刚公布了全新中型SUV CS85的预售价格,售价区间为14.99-17.19万元,成为长安首款轿跑SUV。"
["title"] => string(142) "测试点播最近长安刚刚公布了全新中型SUV CS85的预售价格,售价区间为14.99-17.19万元,成为长安首款轿跑SUV。"
["user_id"] => int(51)
["limit"] => string(19) "2019-10-17 15:03:14"
}
[4] => array(10) {
["opid"] => int(0)
["pid"] => int(8)
["price"] => string(4) "0.00"
["controller"] => string(4) "Shop"
["type_mold"] => int(4)
["img"] => string(0) ""
["description"] => string(0) ""
["title"] => string(3) "111"
["user_id"] => int(51)
["limit"] => string(19) "2019-10-17 15:03:14"
}
[5] => array(10) {
["opid"] => int(0)
["pid"] => int(61)
["price"] => string(4) "0.00"
["controller"] => string(9) "Testpaper"
["type_mold"] => int(3)
["img"] => string(45) "20190403/c378d2084ec9c3f05ceab36c00ac67a4.png"
["description"] => string(6) "健康"
["title"] => string(12) "健康管理"
["user_id"] => int(51)
["limit"] => string(19) "2022-01-14 15:03:14"
}
[6] => array(10) {
["opid"] => int(0)
["pid"] => int(55)
["price"] => string(4) "0.00"
["controller"] => string(9) "Testpaper"
["type_mold"] => int(3)
["img"] => string(45) "20190330/af4db555769d71589ae163bfd0a3c05b.jpg"
["description"] => string(3) "111"
["title"] => string(27) "模板导入试卷测试一"
["user_id"] => int(51)
["limit"] => string(19) "2019-05-01 15:03:14"
}
[7] => array(10) {
["opid"] => int(0)
["pid"] => int(62)
["price"] => string(7) "1000.00"
["controller"] => string(9) "Testpaper"
["type_mold"] => int(3)
["img"] => string(45) "20190330/f1cc9c7df38108c505338a529e3d06a6.jpg"
["description"] => string(18) "法学概论201704"
["title"] => string(18) "法学概论201704"
["user_id"] => int(51)
["limit"] => string(19) "2019-07-29 15:03:14"
}
}
方法:
foreach($pid_arr_t as $key=>$value){
$value['opid'] = 123;
$pid_arr_t[$key] = $value;
}
只有修改opid的元素值
以上就是php怎么遍历数组替换数组中的元素的值的详细内容,更多请关注php爱好者其它相关文章!
-
C#Readonly和Const的区别(定义、类型限制、内存消耗、性能和用法) 时间:2025-11-21 -
PHP目录分隔符DIRECTORY_SEPARATOR常量用法详解 时间:2025-11-21 -
awk数组用法详解(创建、删除、检查、遍历、排序等) 时间:2025-11-21 -
ActionContext构造函数详解 时间:2025-11-21 -
Android ArrayAdapter适配器作用及用法详解 时间:2025-11-21 -
什么是数据库备份?数据库备份有几种方式? 时间:2025-11-21
今日更新
-
洛克王国世界有哪些强力宠物-强力宠物强度排行
阅读:18
-
山海经的梗是什么梗?揭秘上古神兽爆笑现代梗,看完秒懂不迷路!
阅读:18
-
辉烬哪些角色强度高-辉烬t0角色排行推荐
阅读:18
-
夸克网页版直达入口 夸克浏览器极速网页版入口
阅读:18
-
欧易产品设计缺陷引发砸盘 用户损失如何避免
阅读:18
-
镭明闪击有哪些职业-镭明闪击职业机制解析
阅读:18
-
百战群英等级上限怎么提升-百战群英升级方法
阅读:18
-
加密货币交易到底怎么运作?永续合约与杠杆的差异全解析
阅读:18
-
风之痕迹技能怎么选-风之痕迹技能搭配
阅读:18
-
百战群英5星升6星怎么操作-升星方法详解
阅读:18










