Array_Map using multiple native callbacks? Array_Map using multiple native callbacks? php php

Array_Map using multiple native callbacks?


You'll have to do it like this:

$exclude = array_map(function($item) {    return mysql_real_escape_string(strtoupper(trim($item)));}, explode("\n", variable_get('gs_stats_filter', 'googlebot')));


You could also do something like:

  $exclude = array_map(function($item) {     return trim(strtoupper(mysql_real_escape_string($item)));  }, explode(...));

or something. Pass in an anonymous function that does all that stuff.

Hope that helps.

Good luck :)


Yes, just pass the result of one mapping into another:

$result = array_map(    'mysql_real_escape_string',    array_map(        'trim',        array_map(            'strtoupper',            $your_array        )    ));

You can also use a callback in PHP 5.3+:

$result = array_map(function($x){    return mysql_real_escape_string(trim(strtoupper($x)));}, $your_array);

or earlier (in versions of PHP lower than 5.3):

$result = array_map(    create_function('$x','return mysql_real_escape_string(trim(strtoupper($x)));'),    $your_array);