3v4l.org

run code in 300+ 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}
number of ops:  14
compiled vars:  !0 = $town
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        INIT_FCALL                                               'sprintf'
   15     2        SEND_VAL                                                 '%25s+is+a+town+in+%25s+%28%25s%29.'
   16     3        FETCH_DIM_R                                      ~2      !0, 'name'
          4        SEND_VAL                                                 ~2
   17     5        FETCH_DIM_R                                      ~3      !0, 'state'
          6        SEND_VAL                                                 ~3
   18     7        FETCH_DIM_R                                      ~4      !0, 'region'
          8        SEND_VAL                                                 ~4
   14     9        DO_ICALL                                         $5      
         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}
number of ops:  9
compiled vars:  !0 = $town
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'strpos'
          2        FETCH_DIM_R                                      ~1      !0, 'name'
          3        SEND_VAL                                                 ~1
          4        SEND_VAL                                                 'A'
          5        DO_ICALL                                         $2      
          6        IS_IDENTICAL                                     ~3      $2, 0
          7      > RETURN                                                   ~3
          8*     > 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}
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.0.0


preferences:
146.59 ms | 1013 KiB | 20 Q