0

I have something like this:

public static function lengtOfElements($array){
    return array_map(function($item){return strlen($item);},$array);
}

What I want to do is to use strlen($string) directly in array_map, but when I try it it won't work.. Why is the reason?

Something like this:

public static function lengtOfElements($array){
    return array_map(strlen($string),$array);
}
mickmackusa
  • 43,625
  • 12
  • 83
  • 136
Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
  • 1
    because strlen is called ONCE, before array_map even starts, and its returned value is passed in to array_map as a static value. – Marc B Jan 23 '13 at 16:49

1 Answers1

7

Your syntax is a little off:

return array_map('strlen',$array);
John Conde
  • 217,595
  • 99
  • 455
  • 496