Question

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);
}
Was it helpful?

Solution

Your syntax is a little off:

return array_map('strlen',$array);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top