且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过 foreach 循环修改数组的值?

更新时间:2022-01-04 02:45:48

两种方式,可以直接改变当前值共享的内存位置,或者使用源数组访问该值.

Two ways, you can alter the memory location shared by the current value directly, or access the value using the source array.

// Memory reference
foreach ($bizaddarray as &$value) {
    $value = strip_tags(ucwords(strtolower($value)));
}
unset($value); # remove the reference

// Use source array
foreach ($bizaddarray as $key => $value) {
    $bizaddarray[$key] = strip_tags(ucwords(strtolower($value)));
}