Blogger Information
Blog 10
fans 0
comment 0
visits 6971
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
foreach循环中需要引用时用闭包替代
礼物粑粑
Original
591 people have browsed it

话不多说,直接上代码

  1. // 如果你需要这样写
  2. foreach ($arr as &$item) {
  3. $item['a'] = 'a';
  4. }
  5. // 若后续还会遍历此数组,为了避免因引用对后面的影响,最好转成这样写
  6. array_walk($arr, function (&$item) {
  7. $item['a'] = 'a';
  8. });

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post