3v4l.org

run code in 500+ PHP versions simultaneously
<?php $citiesJson = <<<JSON [{"id":"AA0","name":"Aalen","region":"Süden","state":"Baden-Württemberg"}, {"id":"AB0","name":"Aschaffenburg","region":"Mitte","state":"Bayern"}, {"id":"AC0","name":"Aachen","region":"Westen","state":"Nordrhein-Westfalen"}, {"id":"WIT","name":"Witten","region":"Westen","state":"Nordrhein-Westfalen"}, {"id":"DN0","name":"Düren","region":"Westen","state":"Nordrhein-Westfalen"}] JSON; $cities = json_decode($citiesJson, true); $cities = array_map(function(array $city) { $city['city_region_state'] = sprintf( '%s, %s, %s', $city['name'], $city['region'], $city['state'] ); return $city; }, $cities); $citiesByState = array_reduce($cities, function(array $found, array $city) { $found[$city['state']][] = $city; return $found; }, []); echo json_encode($citiesByState, JSON_PRETTY_PRINT);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/skMWu
function name:  (null)
number of ops:  25
compiled vars:  !0 = $citiesJson, !1 = $cities, !2 = $citiesByState
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%5B%7B%22id%22%3A%22AA0%22%2C%22name%22%3A%22Aalen%22%2C%22region%22%3A%22S%C3%BCden%22%2C%22state%22%3A%22Baden-W%C3%BCrttemberg%22%7D%2C%0A%7B%22id%22%3A%22AB0%22%2C%22name%22%3A%22Aschaffenburg%22%2C%22region%22%3A%22Mitte%22%2C%22state%22%3A%22Bayern%22%7D%2C%0A%7B%22id%22%3A%22AC0%22%2C%22name%22%3A%22Aachen%22%2C%22region%22%3A%22Westen%22%2C%22state%22%3A%22Nordrhein-Westfalen%22%7D%2C%0A%7B%22id%22%3A%22WIT%22%2C%22name%22%3A%22Witten%22%2C%22region%22%3A%22Westen%22%2C%22state%22%3A%22Nordrhein-Westfalen%22%7D%2C%0A%7B%22id%22%3A%22DN0%22%2C%22name%22%3A%22D%C3%BCren%22%2C%22region%22%3A%22Westen%22%2C%22state%22%3A%22Nordrhein-Westfalen%22%7D%5D'
   11     1        INIT_FCALL                                                   'json_decode'
          2        SEND_VAR                                                     !0
          3        SEND_VAL                                                     <true>
          4        DO_ICALL                                             $4      
          5        ASSIGN                                                       !1, $4
   13     6        INIT_FCALL                                                   'array_map'
          7        DECLARE_LAMBDA_FUNCTION                              ~6      [0]
   22     8        SEND_VAL                                                     ~6
          9        SEND_VAR                                                     !1
   13    10        DO_ICALL                                             $7      
         11        ASSIGN                                                       !1, $7
   24    12        INIT_FCALL                                                   'array_reduce'
         13        SEND_VAR                                                     !1
         14        DECLARE_LAMBDA_FUNCTION                              ~9      [1]
   28    15        SEND_VAL                                                     ~9
         16        SEND_VAL                                                     <array>
   24    17        DO_ICALL                                             $10     
         18        ASSIGN                                                       !2, $10
   30    19        INIT_FCALL                                                   'json_encode'
         20        SEND_VAR                                                     !2
         21        SEND_VAL                                                     128
         22        DO_ICALL                                             $12     
         23        ECHO                                                         $12
         24      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/skMWu
function name:  {closure:/in/skMWu:13}
number of ops:  13
compiled vars:  !0 = $city
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   RECV                                                 !0      
   16     1        FETCH_DIM_R                                          ~2      !0, 'name'
   17     2        FETCH_DIM_R                                          ~3      !0, 'region'
   18     3        FETCH_DIM_R                                          ~4      !0, 'state'
          4        ROPE_INIT                                         5  ~6      ~2
          5        ROPE_ADD                                          1  ~6      ~6, '%2C+'
          6        ROPE_ADD                                          2  ~6      ~6, ~3
          7        ROPE_ADD                                          3  ~6      ~6, '%2C+'
          8        ROPE_END                                          4  ~5      ~6, ~4
   14     9        ASSIGN_DIM                                                   !0, 'city_region_state'
   18    10        OP_DATA                                                      ~5
   21    11      > RETURN                                                       !0
   22    12*     > RETURN                                                       null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/skMWu
function name:  {closure:/in/skMWu:24}
number of ops:  8
compiled vars:  !0 = $found, !1 = $city
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   25     2        FETCH_DIM_R                                          ~2      !1, 'state'
          3        FETCH_DIM_W                                          $3      !0, ~2
          4        ASSIGN_DIM                                                   $3
          5        OP_DATA                                                      !1
   27     6      > RETURN                                                       !0
   28     7*     > RETURN                                                       null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
220.63 ms | 2082 KiB | 17 Q