Avatar of Colin Brazier
Colin Brazier
Flag 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.


PHP

Avatar of undefined
Last Comment
Chris Stanyon

8/22/2022 - Mon