function trim_r($arr)
{
return is_array($arr) ? array_map('trim_r', $arr) : trim($arr);
}
very helpful.
However, instead of creating a new function, you could just use the trim function as the callback for array_map, for example:
array_map('trim', $arr);
array_map — Applies the callback to the elements of the given arrays
Report a bug Description
array array_map ( callable $callback , array $arr1 [, array $... ] )
array_map() returns an array containing all the elements of arr1 after applying the callback function to each one. The number of parameters that the callback function accepts should match the number of arrays passed to the array_map()
Report a bug Parameters
callback
Callback function to run for each element in each array.
arr1
An array to run through the callback function.
array
Variable list of array arguments to run through the callback function.
{
return is_array($arr) ? array_map('trim_r', $arr) : trim($arr);
}
very helpful.
However, instead of creating a new function, you could just use the trim function as the callback for array_map, for example:
array_map('trim', $arr);
array_map — Applies the callback to the elements of the given arrays
Report a bug Description
array array_map ( callable $callback , array $arr1 [, array $... ] )
array_map() returns an array containing all the elements of arr1 after applying the callback function to each one. The number of parameters that the callback function accepts should match the number of arrays passed to the array_map()
Report a bug Parameters
callback
Callback function to run for each element in each array.
arr1
An array to run through the callback function.
array
Variable list of array arguments to run through the callback function.
0朵
0个