3v4l.org

run code in 500+ PHP versions simultaneously
<?php $townsJson = <<<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; $towns = json_decode($townsJson, true); $towns = array_map(function(array $town) { $town['description'] = sprintf( '%s is a town in %s (%s).', $town['name'], $town['state'], $town['region'] ); return $town; }, $towns); $ATowns = array_filter($towns, fn(array $town) => strpos($town['name'], 'A') === 0); $townsByRegion = array_reduce($towns, function(array $found, array $town) { $found[$town['region']][] = $town; return $found; }, []); var_dump($towns, $ATowns, $townsByRegion);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HZJpG
function name:  (null)
number of ops:  31
compiled vars:  !0 = $townsJson, !1 = $towns, !2 = $ATowns, !3 = $townsByRegion
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                                             $5      
          5        ASSIGN                                                       !1, $5
   13     6        INIT_FCALL                                                   'array_map'
          7        DECLARE_LAMBDA_FUNCTION                              ~7      [0]
   22     8        SEND_VAL                                                     ~7
          9        SEND_VAR                                                     !1
   13    10        DO_ICALL                                             $8      
         11        ASSIGN                                                       !1, $8
   24    12        INIT_FCALL                                                   'array_filter'
         13        SEND_VAR                                                     !1
         14        DECLARE_LAMBDA_FUNCTION                              ~10     [1]
         15        SEND_VAL                                                     ~10
         16        DO_ICALL                                             $11     
         17        ASSIGN                                                       !2, $11
   26    18        INIT_FCALL                                                   'array_reduce'
         19        SEND_VAR                                                     !1
         20        DECLARE_LAMBDA_FUNCTION                              ~13     [2]
   30    21        SEND_VAL                                                     ~13
         22        SEND_VAL                                                     <array>
   26    23        DO_ICALL                                             $14     
         24        ASSIGN                                                       !3, $14
   32    25        INIT_FCALL                                                   'var_dump'
         26        SEND_VAR                                                     !1
         27        SEND_VAR                                                     !2
         28        SEND_VAR                                                     !3
         29        DO_ICALL                                                     
         30      > 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/HZJpG
function name:  {closure:/in/HZJpG:13}
number of ops:  14
compiled vars:  !0 = $town
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, 'state'
   18     3        FETCH_DIM_R                                          ~4      !0, 'region'
          4        ROPE_INIT                                         6  ~6      ~2
          5        ROPE_ADD                                          1  ~6      ~6, '+is+a+town+in+'
          6        ROPE_ADD                                          2  ~6      ~6, ~3
          7        ROPE_ADD                                          3  ~6      ~6, '+%28'
          8        ROPE_ADD                                          4  ~6      ~6, ~4
          9        ROPE_END                                          5  ~5      ~6, '%29.'
   14    10        ASSIGN_DIM                                                   !0, 'description'
   18    11        OP_DATA                                                      ~5
   21    12      > RETURN                                                       !0
   22    13*     > 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/HZJpG
function name:  {closure:/in/HZJpG:24}
number of ops:  6
compiled vars:  !0 = $town
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   RECV                                                 !0      
          1        FETCH_DIM_R                                          ~1      !0, 'name'
          2        FRAMELESS_ICALL_2                strpos              ~2      ~1, 'A'
          3        IS_IDENTICAL                                         ~3      ~2, 0
          4      > RETURN                                                       ~3
          5*     > RETURN                                                       null

End of Dynamic Function 1

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

End of Dynamic Function 2

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.29 ms | 2587 KiB | 18 Q