title: Formatting json to geojson via PHP
body: <p>I am trying to get some data that I have called from a mySQL database to correctly display in a GeoJSON format. Here's some of my PHP code:</p>
  
  <pre><code>$data = array(); //setting up an empty PHP array for the data to go into
  
  if($result = mysqli_query($db,$query)) {
    while ($row = mysqli_fetch_assoc($result))
    {
      $data[] = $row;
    }
  }
  
  $jsonData =json_encode($data);
  $original_data = json_decode($jsonData, true);
  $coordinates = array();
  foreach($original_data as $key =&gt; $value) {
      $coordinates[] = array($value['latitude'], $value['longitude']);
  }
  $new_data = array(
      'type' =&gt; 'FeatureCollection',
      'features' =&gt; array(array(
          'type' =&gt; 'Feature',
      'properties' =&gt; array('time' =&gt; $value['time']),
      'geometry' =&gt; array('type' =&gt; 'Point', 'coordinates' =&gt; $coordinates),
      ),
      ),
  );
  
  $final_data = json_encode($new_data, JSON_PRETTY_PRINT);
  print_r($final_data);
  </code></pre>
  
  <p>I've managed to get my results to look like this so far:
  <a href="https://i.stack.imgur.com/WQgSB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WQgSB.png" alt="enter image description here"></a></p>
  
  <p>But I need them to look like this so that every set of coordinates has its own "type" and "properties" key-value pair:</p>
  
  <p><a href="https://i.stack.imgur.com/uZXtH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uZXtH.png" alt="enter image description here"></a></p>
  
  <p>I've already found some help with this issue <a href="https://stackoverflow.com/questions/24275119/reformatting-json-to-geojson-in-php-laravel">here</a>, but I just can't manage to get over this last formatting hurdle...</p>