HiveBrain v1.2.0
Get Started
← Back to all entries
patternphpModerate

Do nothing lamda...

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
nothinglamdastackoverflow

Problem

$privilegeStrings = array_filter($privileges, function ($s) { return is_string($s); } );


Is there a better way to specify that I want just the string values in the given array?

Solution

You could do:

$privilegeStrings = array_filter($privileges, 'is_string');


array_filter passes every value of the array to the specified function. So you can just specify the function name and everything will be taken care of.

Reference

Code Snippets

$privilegeStrings = array_filter($privileges, 'is_string');

Context

StackExchange Code Review Q#1129, answer score: 11

Revisions (0)

No revisions yet.