-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
  • 6,475
  • 3
  • 29
  • 51
Gayan
  • 2,845
  • 7
  • 33
  • 60

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,680
  • 5
  • 37
  • 44
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
  • 6,475
  • 3
  • 29
  • 51