title: How can i pass a single additional argument to array_map callback in PHP?
body: <p>How can i pass a <strong>single additional argument</strong> to <code>array_map</code> callback? In my example i'd like to pass <code>$smsPattern</code> (as a second argument, after current element in <code>$featureNames</code>) to the function <code>array_map</code> with <code>$getLimit</code> closure:</p>
  
  <pre><code>$features = $usage-&gt;getSubscription()-&gt;getUser()-&gt;getRoles();
  
  // SMS regular expression in the form of ROLE_SEND_SMS_X
  $smsPattern = '/^ROLE_SEND_SMS_(?P&lt;l&gt;\d+)$/i';
  
  // Function to get roles names and X from a role name
  $getNames = function($r) { return trim($r-&gt;getRole()); };
  $getLimit = function($name, $pattern) {
      if(preg_match($pattern, $name, $m)) return $m['l'];
  };
  
  // Get roles names and their limits ignoring null values with array_filter
  $featuresNames = array_map($getNames, $features);
  $smsLimits     = array_filter(array_map($getLimit,  $featureNames, $smsPattern));
  </code></pre>
  
  <p>With this code i'm getting a weird warning:</p>
  
  <blockquote>
    <p>Warning: array_map() [function.array-map]: Argument #3 should
    be an array.</p>
  </blockquote>
  
  <p>Of course di reason is for reusing <code>$getLimit</code> closure with another regular expression like <code>$smsPattern</code>. Thanks.</p>