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