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"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 30
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 30
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/eI29a
function name:  (null)
number of ops:  32
compiled vars:  !0 = $json, !1 = $json_data, !2 = $shops, !3 = $distances
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%7B%0A++%22shops%22%3A+%5B%0A+++%7B%0A++++++%22shop_id%22%3A+%22100%22%2C%0A++++++++++%22locations%22%3A+%5B%0A++++++++++++++++%7B+%22location_id%22%3A+%22100_1%22%2C+%22distance%22%3A+%2210.3%22+%7D%2C%0A++++++++++++++++%7B+%22location_id%22%3A+%22100_2%22%2C+%22distance%22%3A+%2215.2%22+%7D%0A++++++++++%5D%0A++++%7D%2C%0A++++%7B%0A++++++%22shop_id%22%3A+%22101%22%2C%0A++++++++++%22locations%22%3A+%5B%0A++++++++++++++++%7B+%22location_id%22%3A+%22101_1%22%2C+%22distance%22%3A+%2219.3%22+%7D%2C%0A++++++++++++++++%7B+%22location_id%22%3A+%22101_2%22%2C+%22distance%22%3A+%2212.4%22+%7D%0A++++++++++%5D%0A++++%7D%5D%0A%7D'
   21     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !1, $5
   24     6        FETCH_DIM_R                                      ~7      !1, 'shops'
          7      > FE_RESET_R                                       $8      ~7, ->30
          8    > > FE_FETCH_R                                               $8, !2, ->30
   25     9    >   INIT_FCALL                                               'array_column'
         10        FETCH_DIM_R                                      ~9      !2, 'locations'
         11        SEND_VAL                                                 ~9
         12        SEND_VAL                                                 'distance'
         13        SEND_VAL                                                 'location_id'
         14        DO_ICALL                                         $10     
         15        ASSIGN                                                   !3, $10
   26    16        INIT_FCALL                                               'asort'
         17        SEND_REF                                                 !3
         18        DO_ICALL                                                 
   27    19        INIT_FCALL                                               'key'
         20        SEND_VAR                                                 !3
         21        DO_ICALL                                         $13     
         22        CONCAT                                           ~14     $13, '+-%3E+'
         23        INIT_FCALL                                               'current'
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                         $15     
         26        CONCAT                                           ~16     ~14, $15
         27        CONCAT                                           ~17     ~16, '%0A'
         28        ECHO                                                     ~17
   24    29      > JMP                                                      ->8
         30    >   FE_FREE                                                  $8
   28    31      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.15 ms | 1005 KiB | 18 Q