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);
$v is now the pointer, and //trim() call // ur.... is ment as $v = trim($v); $v = urlencode($v); return $v;return $v;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);
array_mapaccepts string" -- The first argument ofarray_map()is a callable. There are 6 types of callables in PHP (see the examples on the documentation), you can easily find one that matches your project and coding style.return array_map('trim', array_map('urlencode', $targets));