function outer_function() {
$nid = 3;
function exists($var) {
print $nid;
return $var->nid == $nid;
}
$a_filtered_array = array_filter($an_array, "exists");
}
I’m trying to filter this array using a variable that’s defined in the outer function, but the variable is not defined. This would work in JS. What am I doing wrong here? How would I accomplish this in PHP?
You could write this (correctly) as:
You can’t just pass a string containing the function’s name. You could also write
See http://www.php.net/manual/en/functions.anonymous.php for in-depth on the syntax and semantics.