本文操作环境: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怎么遍历数组替换数组中的元素的值的详细内容,更多请关注亿码酷站其它相关文章!
php怎么遍历数组替换数组中的元素的值
—–文章转载自PHP中文网如有侵权请联系ymkuzhan@126.com删除
转载请注明来源:php怎么遍历数组替换数组中的元素的值
本文永久链接地址:https://www.ymkuzhan.com/31509.html
本文永久链接地址:https://www.ymkuzhan.com/31509.html
下载声明:
本站资源如无特殊说明默认解压密码为www.ymkuzhan.com建议使用WinRAR解压; 本站资源来源于用户分享、互换、购买以及网络收集等渠道,本站不提供任何技术服务及有偿服务,资源仅提供给大家学习研究请勿作它用。 赞助本站仅为维持服务器日常运行并非购买程序及源码费用因此不提供任何技术支持,如果你喜欢该程序,请购买正版! 版权声明:
下载本站资源学习研究的默认同意本站【版权声明】若本站提供的资源侵犯到你的权益,请提交版权证明文件至邮箱ymkuzhan#126.com(将#替换为@)站长将会在三个工作日内为您删除。 免责声明:
您好,本站所有资源(包括但不限于:源码、素材、工具、字体、图像、模板等)均为用户分享、互换、购买以及网络收集而来,并未取得原始权利人授权,因此禁止一切商用行为,仅可用于个人研究学习使用。请务必于下载后24小时内彻底删除,一切因下载人使用所引起的法律相关责任,包括但不限于:侵权,索赔,法律责任,刑事责任等相关责任,全部由下载人/使用人,全部承担。以上说明,一经发布视为您已全部阅读,理解、同意以上内容,如对以上内容持有异议,请勿下载,谢谢配合!支持正版,人人有责,如不慎对您的合法权益构成侵犯,请联系我们对相应内容进行删除,谢谢!