当前位置:Gxlcms > PHP教程 > php数组如何修改值

php数组如何修改值

时间:2021-07-01 10:21:17 帮助过:23人阅读

php数组修改值的方法:首先创建一个PHP示例文件;然后通过“foreach($pid_arr_t as $key=>$value){$value['opid'] = 123;...}”方法修改数组中某个元素值即可。

推荐:《PHP视频教程》

php 修改数据中某个元素值,其它元素值不变。

循环数组

  1. array(8) {
  2. [0] => array(10) {
  3. ["opid"] => int(0)
  4. ["pid"] => int(11)
  5. ["price"] => string(4) "0.10"
  6. ["controller"] => string(4) "Live"
  7. ["type_mold"] => int(1)
  8. ["img"] => string(0) ""
  9. ["description"] => string(4) "1212"
  10. ["title"] => string(12) "测试回放"
  11. ["user_id"] => int(51)
  12. ["limit"] => string(19) "2020-01-25 15:03:14"
  13. }
  14. [1] => array(10) {
  15. ["opid"] => int(0)
  16. ["pid"] => int(10)
  17. ["price"] => string(4) "0.10"
  18. ["controller"] => string(4) "Live"
  19. ["type_mold"] => int(1)
  20. ["img"] => string(0) ""
  21. ["description"] => string(2) "12"
  22. ["title"] => string(12) "线上测试"
  23. ["user_id"] => int(51)
  24. ["limit"] => string(19) "2019-10-17 15:03:14"
  25. }
  26. [2] => array(10) {
  27. ["opid"] => int(0)
  28. ["pid"] => int(3)
  29. ["price"] => string(4) "1.00"
  30. ["controller"] => string(4) "Live"
  31. ["type_mold"] => int(1)
  32. ["img"] => string(0) ""
  33. ["description"] => string(4) "1212"
  34. ["title"] => string(21) "测试保长时直播"
  35. ["user_id"] => int(51)
  36. ["limit"] => string(19) "2019-10-17 15:03:14"
  37. }
  38. [3] => array(10) {
  39. ["opid"] => int(0)
  40. ["pid"] => int(2)
  41. ["price"] => string(4) "0.10"
  42. ["controller"] => string(5) "Video"
  43. ["type_mold"] => int(2)
  44. ["img"] => string(0) ""
  45. ["description"] => string(130) "最近长安刚刚公布了全新中型SUV CS85的预售价格,售价区间为14.99-17.19万元,成为长安首款轿跑SUV。"
  46. ["title"] => string(142) "测试点播最近长安刚刚公布了全新中型SUV CS85的预售价格,售价区间为14.99-17.19万元,成为长安首款轿跑SUV。"
  47. ["user_id"] => int(51)
  48. ["limit"] => string(19) "2019-10-17 15:03:14"
  49. }
  50. [4] => array(10) {
  51. ["opid"] => int(0)
  52. ["pid"] => int(8)
  53. ["price"] => string(4) "0.00"
  54. ["controller"] => string(4) "Shop"
  55. ["type_mold"] => int(4)
  56. ["img"] => string(0) ""
  57. ["description"] => string(0) ""
  58. ["title"] => string(3) "111"
  59. ["user_id"] => int(51)
  60. ["limit"] => string(19) "2019-10-17 15:03:14"
  61. }
  62. [5] => array(10) {
  63. ["opid"] => int(0)
  64. ["pid"] => int(61)
  65. ["price"] => string(4) "0.00"
  66. ["controller"] => string(9) "Testpaper"
  67. ["type_mold"] => int(3)
  68. ["img"] => string(45) "20190403/c378d2084ec9c3f05ceab36c00ac67a4.png"
  69. ["description"] => string(6) "健康"
  70. ["title"] => string(12) "健康管理"
  71. ["user_id"] => int(51)
  72. ["limit"] => string(19) "2022-01-14 15:03:14"
  73. }
  74. [6] => array(10) {
  75. ["opid"] => int(0)
  76. ["pid"] => int(55)
  77. ["price"] => string(4) "0.00"
  78. ["controller"] => string(9) "Testpaper"
  79. ["type_mold"] => int(3)
  80. ["img"] => string(45) "20190330/af4db555769d71589ae163bfd0a3c05b.jpg"
  81. ["description"] => string(3) "111"
  82. ["title"] => string(27) "模板导入试卷测试一"
  83. ["user_id"] => int(51)
  84. ["limit"] => string(19) "2019-05-01 15:03:14"
  85. }
  86. [7] => array(10) {
  87. ["opid"] => int(0)
  88. ["pid"] => int(62)
  89. ["price"] => string(7) "1000.00"
  90. ["controller"] => string(9) "Testpaper"
  91. ["type_mold"] => int(3)
  92. ["img"] => string(45) "20190330/f1cc9c7df38108c505338a529e3d06a6.jpg"
  93. ["description"] => string(18) "法学概论201704"
  94. ["title"] => string(18) "法学概论201704"
  95. ["user_id"] => int(51)
  96. ["limit"] => string(19) "2019-07-29 15:03:14"
  97. }
  98. }

方法:

  1. foreach($pid_arr_t as $key=>$value){
  2. $value['opid'] = 123;
  3. $pid_arr_t[$key] = $value;
  4. }

只有修改opid的元素值.

以上就是php数组如何修改值的详细内容,更多请关注gxlcms其它相关文章!

人气教程排行