Reputation: 68
Let's say I have the following PHP variables:
$colors = array( 'red', 'green', 'blue', 'yellow', 'brown' );
$skey = 'ow';
How can I filter $colors
using $skey
to get an array which only contain 'yellow' and 'brown'?
Upvotes: 1
Views: 58
Reputation: 26431
Use array_filter,
$results = array_filter($colors, function($var){ return strpos($var, 'ow') !== false; });
DEMO.
Upvotes: 3