3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '{ "shops": [ { "shop_id": "100", "locations": [ { "location_id": "100_1", "distance": "10.3" }, { "location_id": "100_2", "distance": "15.2" } ] }, { "shop_id": "101", "locations": [ { "location_id": "101_1", "distance": "19.3" }, { "location_id": "101_2", "distance": "12.4" } ] }] }'; // Decode the JSON data $json_data = json_decode($json,true); // Do a foreach loop foreach($json_data['shops'] as $shops) { $distances = array_column($shops['locations'], 'distance','location_id'); asort($distances); echo key($distances) . ' -> ' . current($distances) . "\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
100_1 -> 10.3 101_2 -> 12.4

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:
24.64 ms | 405 KiB | 5 Q