如何通过foreach循环修改数组的值? [英] How to modify an array's values by a foreach loop?

查看:846
本文介绍了如何通过foreach循环修改数组的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个foreach循环 - 我想根据我的修改值修改数组。但是,当我尝试以后将$ bizaddarray转换为字符串时,所有的HTML标签仍然存在。这是我的foreach循环 - 我怎样才能使带标签永久?

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


解决方案



  //内存引用$ b $内存位置直接由当前值共享,或者使用源数组访问该值。 b foreach($ bizaddarray as& $ value){
$ value = strip_tags(ucwords(strtolower($ value)));
}
unset($ value); #删除引用

或者
<$ p $ (


izaddarray [$ key] = strip_tags(ucwords(strtolower($ value)); //使用源数组
foreach($ bizaddarray as $ key => $ value) )));
}


So I have 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循环修改数组的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆