Link to home
Start Free TrialLog in
Avatar of Colin Brazier
Colin BrazierFlag for United Kingdom of Great Britain and Northern Ireland

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?

$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');
         });
      }

Open in new window



Thanks.


ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Colin Brazier

ASKER

Ah!  Thanks Chris.
No worries :)