Alex Rivera | Logout

Array_Map using multiple native callbacks?

Asked 2012-01-06T23:05:32.033
14

I want to run 3 native functions on the same array: trim, strtoupper and mysql_real_escape_string. Can this be done?

Trying to pass an array as a callback like this isn't working:

$exclude = array_map(array('trim','strtoupper','mysql_real_escape_string'), explode("\n", variable_get('gs_stats_filter', 'googlebot')));

Although this works fine because it's only using one native function as the callback:

$exclude = array_map('trim', explode("\n", variable_get('gs_stats_filter', 'googlebot')));
Edit
Report

1 Answer

5

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 :)

answered 2012-01-06T23:08:41.033

Your Answer