title: Get Array data outside while loop - php
body: <p>I want to create a function to pass the values of the weeks of the year and starting date of that week. I only get output while I put the print_r($week_array) inside the while loop (which is not useful) I need to be able to get the array outside the loop. I can't see here what is happening.... Thanks.</p>
  
  <pre><code>function GetWeeks(){
      $year = date('Y');
      $firstDayOfYear = mktime(0, 0, 0, 1, 1, $year);
      $firstthursday = strtotime('thursday', $firstDayOfYear);
      $firstMonday = strtotime('-3 days', $firstthursday);
      $nextMonday = strtotime('monday', $firstDayOfYear);
      $nextSunday = strtotime('sunday', $firstMonday);
      $weeknumber = "1";
      $week_array = '';
  
      while (date('Y', $nextMonday) == $year) {
          if ($weeknumber == 53) { 
              exit; 
          }
  
          if ($weeknumber == 1) {
              $fromdate = date('Y-m-d', $firstMonday);
              $todate   = date('Y-m-d', $nextSunday);
              $week_array[] = array($weeknumber =&gt; $fromdate);
              date('Y-m-d', $firstMonday);
              date('Y-m-d', $nextSunday);
              $weeknumber = $weeknumber + 1;
          }
  
          $nextSunday = strtotime('sunday', $nextMonday);
          $fromdate = date('Y-m-d', $nextMonday);
          $todate = date('Y-m-d', $nextSunday);
          $nextMonday = strtotime('+1 week', $nextMonday);
          $nextSunday = strtotime('+1 week', $nextSunday);
          #array_push($array, $fromdate);
          $week_array[] = array($weeknumber =&gt; $fromdate);
          $weeknumber = $weeknumber + 1;
          print_r($week_array); // Print the array values for each loop.
      }
  
      print_r($week_array); -&gt; Does not work at all (dont print anything)
  
      return array($week_array);
  
  }
  </code></pre>