How to modify an array’s values by a foreach loop?

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

Or

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

Leave a Comment