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);
}
1
  • 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. Commented Jan 23, 2013 at 16:49

1 Answer 1

7

Your syntax is a little off:

return array_map('strlen',$array);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.