Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>$polygon-&gt;polygon-&gt;geometry-&gt;coordinates[0] </code></pre> <p>or</p> <pre><code>$polygon['polygon']['geometry']['coordinates'][0] </code></pre> <p>what you have is a multidimensional array/object not sure which its being output to when decoded in your case as it appears you have a class doing it I would have just used json_decode, but anyway. Yea from the looks of it, polygon is the main object, then in it is geometry which is an object that has type and coordinates, and then coordinates has multiple objects/arrays in it.</p> <p>the above samples if I typed them right will show the first set of coordinates in that object. Of course you could run it through a loop ie:</p> <p>In the case that it is an object assuming your Class decodes as an object and not an array. Not exactly sure what <code>$polygon = CJSON::decode($str,true);</code> does. But if its anything like <code>json_decode()</code> then you should be all set.</p> <p>This is my method of breaking down the object as you present here, its worth noting you may want to check counts, and see if the object is set first, or if the property exists in the object to prevent other means of the code breaking down the road. But what I have here is just pure example at its core, it will server its purpose though. But will not error handle which is why I say you may want to elaborate further on it doing those checks.</p> <p>Anyway heres my code:</p> <pre><code>&lt;?php $str = '{"polygon":{"type":"Feature","properties":[],"geometry":{"type":"Polygon","coordinates":[[[-7302732.4720101,6527844.6333235],[-3193477.8319711,6606116.1502766],[-5111129.9973226,5001550.0527375],[-6637424.5779086,4884142.7773079],[-7772361.5737289,5158093.0866438],[-7302732.4720101,6527844.6333235]]]},"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"}}}}'; $polygon = json_decode($str); echo'&lt;pre&gt;';print_r($polygon);echo'&lt;/pre&gt;'; $set = 1; foreach($polygon-&gt;polygon-&gt;geometry-&gt;coordinates[0] as $coordinates) { echo 'Set '.$set.': ';$set++; echo $coordinates[0].','.$coordinates[1].'&lt;br&gt;'; } ?&gt; </code></pre> <p>see it in action <a href="http://7pz.net/geojson-parse.php" rel="nofollow">http://7pz.net/geojson-parse.php</a> (scroll to the bottom)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload