-1

I wrote php function for get weekend, this "$data['projects']" is not empty, but it is redirect to $end = date("Y-m-d", strtotime('next sunday'));

function weekendignSet(){
     if(!empty($data['projects'])){
         $end = $data['projects'][0]->week_end_day;
      }else{
         if(!empty($_GET['week_ending'])){
             $end = $_GET['week_ending'];
         }else{
             $end = date("Y-m-d", strtotime('next sunday'));
         }
      }
      return $end;
}

What is the error? thank you

Unamata Sanatarai
  • 5,920
  • 3
  • 25
  • 47
Mak
  • 2,765
  • 7
  • 31
  • 56

3 Answers3

0

You need to pass $data to function then it will check in if() else you always goes in else condition try

function weekendignSet($data){

on calling :-

weekendignSet($data);
Rakesh Sharma
  • 13,570
  • 4
  • 35
  • 42
0

Your function needs an input paramater named "$data"

0

Make the $data a global variable, or pass it into a function:

global $data;
$data = array();
function weekendignSet(){
     global $data;
     if(!empty($data['projects'])){
         $end = $data['projects'][0]->week_end_day;
      }else{
         if(!empty($_GET['week_ending'])){
             $end = $_GET['week_ending'];
         }else{
             $end = date("Y-m-d", strtotime('next sunday'));
         }
      }
      return $end;
}

or

$data = array();
function weekendignSet($data){
     if(!empty($data['projects'])){
         $end = $data['projects'][0]->week_end_day;
      }else{
         if(!empty($_GET['week_ending'])){
             $end = $_GET['week_ending'];
         }else{
             $end = date("Y-m-d", strtotime('next sunday'));
         }
      }
      return $end;
}
weekendignSet($data);
Unamata Sanatarai
  • 5,920
  • 3
  • 25
  • 47