Hello,
I’m having some troubles with writing elegant code to filter out elements from php array.
Heres what I want to do:
I have 2 arrays:
$array = array('value 1', 'value 2', 'bleh', 'dont remove me');
$drop = array('value 1', 'bleh');
Now I want to filter // drop elements from $drop out of $array
I tried this (which seems to be the most elegant way to do it):
$filtered_array = array_filter($array, function($element) { return (!in_array($element, $drop)); } );
But I get:
Parse error: syntax error, unexpected T_FUNCTION in /Applications/MAMP/htdocs/ …
I even get the same error if I try to call this (I use PHP 5):
$test = array_filter($drop, function($a) { return !is_null($a) });
What is going on?
Thanks for help