array_map
accepts string as its first argument. Is there a way, to use arrays instead of strings, like:
.... array_map( array('trim','urlencode'), $my_array);
so I could attach multiple functions.
array_map
accepts string as its first argument. Is there a way, to use arrays instead of strings, like:
.... array_map( array('trim','urlencode'), $my_array);
so I could attach multiple functions.
You can define a function to combine these trim
and urlencode
functions. Then use the new function name or the new function as the first parameter of the array_map()
function.
array_map(function($v){
$v = trim($v);
$v = urlencode($v);
return $v
}, $array);
You can do it this way also. Reference: create_function()
Warning: This function has been DEPRECATED as of PHP 7.2.0. Relying on this function is highly discouraged.
Try this here code snippet here
$newfunc = create_function('$value', 'return urlencode(trim($value));');
$array=array_map($newfunc, $array);