3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = ' { "type": "FeatureCollection", "features": [{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [ -4.702540, 51.672791 ] }, "properties": { "Id": "1603", "Name": "TENBY", "Country": "Channel Islands", "ContinuousHeightsAvailable": true } }, { "type": "Feature", "geometry": { "type": "Point", "coordinates": [ -1.878530, 50.721680 ] }, "properties": { "Id": "1603A", "Name": "Bournmouth", "Country": "Channel Islands", "ContinuousHeightsAvailable": true } }, { "type": "Feature", "geometry": { "type": "Point", "coordinates": [ -2.35, 49.433333 ] }, "properties": { "Id": "1603A", "Name": "Maseline Pier", "Country": "Channel Islands", "ContinuousHeightsAvailable": true } }] }'; $locations = json_decode($json, true); #print_r($locations); $base_location = array( 'lat' => "51.672791", 'lng' => "-4.702540" ); $distances = array(); for ($c = 0; $c < count($locations["features"]); $c++) { echo "I = " .$c; } for ($c = 0; $c < count($locations["features"]); $c++) { foreach($locations as $i){ foreach ($i as $z) { foreach ($z['geometry'] as $key => $location) { if ($key == "coordinates"){ # print_r($z); $a = $base_location['lat'] - $location[1]; $b = $base_location['lng'] - $location[0]; $distance = sqrt(($a**2) + ($b**2)); $distances[$c] = $distance; echo "The value of key '$key' is '$location'", PHP_EOL; }} }} } print_r($base_location); asort($distances); print_r($distances); $closest = $location[key($distances)]; #print_r($closest); #echo "<br>Closest port from ARRAY is: " . $closest['features'][1]['properties']['Id'];
Output for git.master, git.master_jit, rfc.property-hooks
I = 0I = 1I = 2 Warning: foreach() argument must be of type array|object, string given in /in/JX0i5 on line 69 Warning: Array to string conversion in /in/JX0i5 on line 78 The value of key 'coordinates' is 'Array' Warning: Array to string conversion in /in/JX0i5 on line 78 The value of key 'coordinates' is 'Array' Warning: Array to string conversion in /in/JX0i5 on line 78 The value of key 'coordinates' is 'Array' Warning: foreach() argument must be of type array|object, string given in /in/JX0i5 on line 69 Warning: Array to string conversion in /in/JX0i5 on line 78 The value of key 'coordinates' is 'Array' Warning: Array to string conversion in /in/JX0i5 on line 78 The value of key 'coordinates' is 'Array' Warning: Array to string conversion in /in/JX0i5 on line 78 The value of key 'coordinates' is 'Array' Warning: foreach() argument must be of type array|object, string given in /in/JX0i5 on line 69 Warning: Array to string conversion in /in/JX0i5 on line 78 The value of key 'coordinates' is 'Array' Warning: Array to string conversion in /in/JX0i5 on line 78 The value of key 'coordinates' is 'Array' Warning: Array to string conversion in /in/JX0i5 on line 78 The value of key 'coordinates' is 'Array' Array ( [lat] => 51.672791 [lng] => -4.702540 ) Array ( [0] => 3.2480173314445 [1] => 3.2480173314445 [2] => 3.2480173314445 )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
33.29 ms | 409 KiB | 5 Q