troubleshooting Question

Using a variable instead of a literal in array_filter callback

Avatar of Colin Brazier
Colin BrazierFlag for United Kingdom of Great Britain and Northern Ireland asked on
PHP
3 Comments1 Solution21 ViewsLast Modified:
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');
         });
      }


Thanks.


Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros