我创建了这个方法来改变数组中的每个值.我是PHP的新手,所以我认为应该有一个更有效的方法来做到这一点.
这是我的代码:
foreach($my_array as $key => $value)
{
$my_array[$key] = htmlentities($value);
}
Run Code Online (Sandbox Code Playgroud)
有一个更好的方法吗?
先感谢您.
使用array_map你可能会更好
$my_array = array_map( 'htmlentities' , $my_array);
Run Code Online (Sandbox Code Playgroud)
您可以引用该数组并进行更改
foreach ($array as &$value) {
$value = $value * 2;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1206 次 |
| 最近记录: |