title: foreach use value from object twice
body: <p>I recieve json objects like the following over an rest-service</p>
  
  <pre><code>[
   {
      "pos_time": "04.09.2018 09:57:02",
      "receivetime": "04.09.2018 09:57:18",
      "latitude": 47554898,
      "longitude": 13173448,
      "speed": 8,
      "course": 359,
      "country": "AT"
    },
    {
      "pos_time": "04.09.2018 09:58:02",
      "receivetime": "04.09.2018 09:58:31",
      "latitude": 47835502,
      "longitude": 13653503,
      "speed": 7,
      "course": 174,
      "country": "AT"
    },
  ]
  </code></pre>
  
  <p>form this json I want to create a geojson "linestring".
  The "linestring" is not the problem. the problem is, that I have to use both coordinates of each object to create the "linestring"
  and I have no idea how to loop through the objects and use the coordinates from the second object and first object to create the "linestring"</p>
  
  <p>the result should look like this:</p>
  
  <pre><code>{
    "type": "FeatureCollection",
    "features": [
      {
        "type": "Feature",
        "properties": {
          "pos_time": "04.09.2018 09:56:22",
          "receivetime": "04.09.2018 09:57:18",
          "course": 177,
          "speed": 2,
          "country": "AT",
          "error": null
        },
        "geometry": {
          "type": "LineString",
          "coordinates": [
            [
              13.173448, // object 1
              47.554898  // object 1
            ],
            [
              13.653503, // object 2
              47.835502  // object 2
            ]
          ]
        }
      }
    ]
  }
  </code></pre>
  
  <p>and the code for the moment looks like this:</p>
  
  <pre><code>        // create geojson
  
      $geojson = array(
          'type' =&gt; 'FeatureCollection',
          'features' =&gt; array()
      );
  
      ///////
  
      foreach ($tomtom_request_array as $key =&gt; $value) {
  
          if (empty($value['longitude']) || empty($value['latitude']))
          {
              $longitude = "13.07202";
              $latitude = "47.889486";
              $error = "Missing or incorrect GPS data";
          }
          else
          {
              $latitude = $value['longitude']; // object 1
              $longitude = $value['latitude']; // object 1
  
              $latitude_previous = $value['longitude']; // object 2
              $longitude_previous = $value['latitude']; // object 2
  
              $error = NULL;
          }
  
          if (empty($value['speed']))
          {
              $speed = "0";
          }
          else
          {
              $speed = $value['speed'];
          }
  
          if (empty($value['course']))
          {
              $course = "0";
          }
          else
          {
              $course = $value['course'];
          }
  
          $feature = array(
                  'type' =&gt; 'Feature',
                  'properties' =&gt; array(
                  'pos_time' =&gt; $value['pos_time'],
                  'receivetime' =&gt; $value['receivetime'],
                  'course' =&gt; $course,
                  'speed' =&gt; $speed,
                  'country' =&gt; $value['country'],
                  'error' =&gt; $error
              ),
                  'geometry' =&gt; array(
                      'type' =&gt; 'LineString',
  
                      'coordinates' =&gt; array(
                          array(($latitude * 0.000001), ($longitude* 0.000001)),
                          array(($latitude_previous * 0.000001), ($longitude_previous* 0.000001))
                          ),            
                      ),
          );
          array_push($geojson['features'], $feature);
      }
      $this-&gt;response($geojson, $response_status);
  }
  </code></pre>
  
  <p>thanks in advance!</p>