this could be a very silly question but I just can't understand how PHP scope is working on this piece of code:
$leagueKey = 'NFL';
$response['response'] = array_filter($response['response'], function($tier){
return ($tier['LeagueKey'] === $leagueKey ? true : false);
});
When I run that, I get an "Undefined variable: leagueKey" exception. On the other hand, this works perfectly well:
$response['response'] = array_filter($response['response'], function($tier){
return ($tier['LeagueKey'] === 'NFL' ? true : false);
});
Why can't PHP see my $leagueKey variable inside the array_filter function?
Thanks!