开发者

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

开发者 https://www.devze.com 2023-04-12 03:43 出处:网络
So I have 开发者_StackOverflow中文版this foreach loop - and I want to modify the array based on my modification of the values. However when I try to later convert $bizaddarray to a string, all of the

So I have 开发者_StackOverflow中文版this foreach loop - and I want to modify the array based on my modification of the values. However when I try to later convert $bizaddarray to a string, all of the HTML tags are still present. Here's my foreach loop - how can I make the strip tags permanent?

    foreach ($bizaddarray as $value) {
        strip_tags(ucwords(strtolower($value)));
    }


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)));
}


foreach ($bizaddarray as $key => $value) {
    $bizaddarray[$key] = ucwords(strtolower($value));
}
0

精彩评论

暂无评论...
验证码 换一张
取 消