Home  >  Article  >  Backend Development  >  请问怎么去掉数组里面所有值两边的空格

请问怎么去掉数组里面所有值两边的空格

WBOY
WBOYOriginal
2016-06-23 13:18:411384browse

请问怎么去掉数组里面所有值两边的空格?
数组可能是一维也可能是二维数组


回复讨论(解决方案)

trim()

$a = array(  ' a', ' b ', 'c ',  array(' a', ' b ', array(' a', ' b ', 'c '),),);array_walk_recursive($a, function(&$v) { $v = trim($v); });var_export($a);
array (  0 => 'a',  1 => 'b',  2 => 'c',  3 =>   array (    0 => 'a',    1 => 'b',    2 =>     array (      0 => 'a',      1 => 'b',      2 => 'c',    ),  ),)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn