3v4l.org

run code in 500+ PHP versions simultaneously
<?php $json = '[ { "name": "A", "children": [ { "name": "B", "children": [ { "name": "C" }, { "name": "D", "children": [ { "name": "E" }, { "name": "F" } ] } ] }, { "name": "G" } ] }, { "name": "H" } ]'; $json = json_decode($json, true); function getArrayValuesRecursively(array $array){ $values = []; foreach ($array as $value) { if (is_array($value)) { $values = array_merge( $values, getArrayValuesRecursively($value) ); } else { $values[] = ['name' => $value]; } } return $values; } echo json_encode(getArrayValuesRecursively($json));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/01Fla
function name:  (null)
number of ops:  14
compiled vars:  !0 = $json
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, '%5B%0A++++%7B%0A++++++++%22name%22%3A+%22A%22%2C%0A++++++++%22children%22%3A+%5B%0A++++++++++++%7B%0A++++++++++++++++%22name%22%3A+%22B%22%2C%0A++++++++++++++++%22children%22%3A+%5B%0A++++++++++++++++++++%7B%0A++++++++++++++++++++++++%22name%22%3A+%22C%22%0A++++++++++++++++++++%7D%2C%0A++++++++++++++++++++%7B%0A++++++++++++++++++++++++%22name%22%3A+%22D%22%2C%0A++++++++++++++++++++++++%22children%22%3A+%5B%0A++++++++++++++++++++++++++++%7B%0A++++++++++++++++++++++++++++++++%22name%22%3A+%22E%22%0A++++++++++++++++++++++++++++%7D%2C%0A++++++++++++++++++++++++++++%7B%0A++++++++++++++++++++++++++++++++%22name%22%3A+%22F%22%0A++++++++++++++++++++++++++++%7D%0A++++++++++++++++++++++++%5D%0A++++++++++++++++++++%7D%0A++++++++++++++++%5D%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A++++++++++++++++%22name%22%3A+%22G%22%0A++++++++++++%7D%0A++++++++%5D%0A++++%7D%2C%0A++++%7B%0A++++++++%22name%22%3A+%22H%22%0A++++%7D%0A++++%5D'
   35     1        INIT_FCALL                                                   'json_decode'
          2        SEND_VAR                                                     !0
          3        SEND_VAL                                                     <true>
          4        DO_ICALL                                             $2      
          5        ASSIGN                                                       !0, $2
   52     6        INIT_FCALL                                                   'json_encode'
          7        INIT_FCALL                                                   'getarrayvaluesrecursively'
          8        SEND_VAR                                                     !0
          9        DO_FCALL                                          0  $4      
         10        SEND_VAR                                                     $4
         11        DO_ICALL                                             $5      
         12        ECHO                                                         $5
         13      > RETURN                                                       1

Function getarrayvaluesrecursively:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 19
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 15
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/01Fla
function name:  getArrayValuesRecursively
number of ops:  22
compiled vars:  !0 = $array, !1 = $values, !2 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   37     0  E >   RECV                                                 !0      
   38     1        ASSIGN                                                       !1, <array>
   39     2      > FE_RESET_R                                           $4      !0, ->19
          3    > > FE_FETCH_R                                                   $4, !2, ->19
   40     4    >   TYPE_CHECK                                      128          !2
          5      > JMPZ                                                         ~5, ->15
   41     6    >   INIT_FCALL                                                   'array_merge'
   42     7        SEND_VAR                                                     !1
   43     8        INIT_FCALL_BY_NAME                                           'getArrayValuesRecursively'
          9        SEND_VAR_EX                                                  !2
         10        DO_FCALL                                          0  $6      
         11        SEND_VAR                                                     $6
   41    12        DO_ICALL                                             $7      
         13        ASSIGN                                                       !1, $7
   40    14      > JMP                                                          ->18
   46    15    >   INIT_ARRAY                                           ~10     !2, 'name'
         16        ASSIGN_DIM                                                   !1
         17        OP_DATA                                                      ~10
   39    18    > > JMP                                                          ->3
         19    >   FE_FREE                                                      $4
   49    20      > RETURN                                                       !1
   50    21*     > RETURN                                                       null

End of function getarrayvaluesrecursively

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.07 ms | 1884 KiB | 17 Q