title: Parsing JSON file to produce and return another JSON with required data
body: <p>I need to parse a given JSON file for events that occur between the start and end time that are passed through an HTTP GET. The events that occur between this range should then be returned as a new JSON encoded response. So far I have come up with two possible solutions. Neither seem to be giving me the expected JSON encoded file.</p>
  
  <p>EDIT: Aside from the script not producing the proper JSON file, I get the following error in the developers console on Chrome: Uncaught TypeError: Cannot read property 'length' of null</p>
  
  <p>Solution 1:</p>
  
  <pre><code>  $param1 = $_GET['startTime'];
    $param2 = $_GET['endTime'];
    $data = file_get_contents('./events.json');
    $json = json_decode($data, true);
  
    foreach ($json as $key =&gt; $value){
          if ($value &gt; $param1 &amp;&amp; $value &lt; $param2) {
                echo "$key =&gt; $value"; }
          else { return; }
    }
  </code></pre>
  
  <p>Solution 2 (same parameters passed in, different for each loop):</p>
  
  <pre><code>  foreach ($json as $key =&gt; $value){
          if ($value &gt;= $param1 &amp;&amp; $value &lt;= $param2) { 
                $tempFile = "tempEvents.json";
                $jsonArray = json_decode(file_get_contents($tempFile), true);
                array_push($jsonArray, array( 'title' =&gt; ????, 'start' =&gt; $param1, 'end' =&gt; $param2 ));
                file_put_contents($file, json_encode($jsonArray));
          }
          else { return; }
          echo json_encode('tempEvents.json');
    }
  </code></pre>
  
  <p>Sample JSON file to be parsed:</p>
  
  <pre><code>  [
     {
      "Name":"Event 1",
      "Start Time":258147369,
      "End Time":369147258
     },
     {
      "Name":"Event 2",
      "Start Time":789456123,
      "End Time":159487263
     },
    ]
  </code></pre>