PHP – 修剪数组元素值没有foreach
发布时间:2020-12-13 21:57:51 所属栏目:PHP教程 来源:网络整理
导读:参见英文答案 How to trim white spaces of array values in php????????????????????????????????????10个 我在php中使用以下代码: 码: $input = array(" text1","text2 "," text3 "," text4");$output = array();foreach($input as $val) { $output[] =
参见英文答案 >
How to trim white spaces of array values in php????????????????????????????????????10个
我在php中使用以下代码: 码: $input = array(" text1","text2 "," text3 "," text4"); $output = array(); foreach($input as $val) { $output[] = trim($val); } var_dump($output); 是否可以在没有foreach循环的情况下修剪数组元素值? 解决方法
你可以使用
array_map :
$output = array_map('trim',$input); 当然,这仍将在内部遍历数组. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |