Colin Brazier
asked on
Using a variable instead of a literal in array_filter callback
In the code, why does the commented out part in bold using a variable in the callback give an error?
The uncommented code works, when I use a literal ('Sat' or 'Sun').
What am I missing?
PS, I am using PHP 5.6............this may be it?
Thanks.
The uncommented code works, when I use a literal ('Sat' or 'Sun').
What am I missing?
PS, I am using PHP 5.6............this may be it?
$short_day = substr($this->long_day,0,3);
$matchDateRowTrOpen = '<tr>';
$matchDateRowTrClose = '</tr>';
// Get only the teams we want - Saturday or Sunday teams - from the array.
/*if ($short_day == 'Sat' || $short_day == 'Sun' )
{
$this->arr_one_day_matches = array_filter($this->arr_one_day_matches, function ($team) {
return ($team['td_class_satsun'] == $short_day);
});
}
*/
// Get only the teams we want - Saturday or Sunday teams - from the array.
if ($short_day == 'Sat')
{
$this->arr_one_day_matches = array_filter($this->arr_one_day_matches, function ($team) {
return ($team['td_class_satsun'] == 'Sat');
});
}
// Get only the teams we want - Saturday or Sunday teams - from the array.
if ($short_day == 'Sun' )
{
$this->arr_one_day_matches = array_filter($this->arr_one_day_matches, function ($team) {
return ($team['td_class_satsun'] == 'Sun');
});
}
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No worries :)
ASKER