3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = [ 0 => [ "id" => "1", "color" => "red", ], 1 => [ 0 => [ "id" => "2", "color" => "blue", ], 1 => [ 0 => [ "id" => "3", "color" => "green", ], ], 2 => [ "id" => "4", "color" => "blue", ], ], 2 => [ "id" => "5", "color" => "purple", ], ]; function flattenArray($arr = []) { $retArr = []; foreach ($arr as $val) { if (is_array($val)) { $retArr[] = array_filter($val, function ($v) { return !is_array($v); }); $retArr = array_merge(array_filter($retArr), flattenArray($val)); } } return $retArr; } $arr = flattenArray($arr); print_r($arr);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iWvnj
function name:  (null)
number of ops:  9
compiled vars:  !0 = $arr
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   49     1        INIT_FCALL                                                   'flattenarray'
          2        SEND_VAR                                                     !0
          3        DO_FCALL                                          0  $2      
          4        ASSIGN                                                       !0, $2
   50     5        INIT_FCALL                                                   'print_r'
          6        SEND_VAR                                                     !0
          7        DO_ICALL                                                     
          8      > RETURN                                                       1

Function flattenarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 25
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 25
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 24
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 24
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/iWvnj
function name:  flattenArray
number of ops:  28
compiled vars:  !0 = $arr, !1 = $retArr, !2 = $val
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   36     0  E >   RECV_INIT                                            !0      <array>
   38     1        ASSIGN                                                       !1, <array>
   39     2      > FE_RESET_R                                           $4      !0, ->25
          3    > > FE_FETCH_R                                                   $4, !2, ->25
   40     4    >   TYPE_CHECK                                      128          !2
          5      > JMPZ                                                         ~5, ->24
   41     6    >   INIT_FCALL                                                   'array_filter'
          7        SEND_VAR                                                     !2
          8        DECLARE_LAMBDA_FUNCTION                              ~7      [0]
   43     9        SEND_VAL                                                     ~7
   41    10        DO_ICALL                                             $8      
         11        ASSIGN_DIM                                                   !1
   43    12        OP_DATA                                                      $8
   44    13        INIT_FCALL                                                   'array_merge'
         14        INIT_FCALL                                                   'array_filter'
         15        SEND_VAR                                                     !1
         16        DO_ICALL                                             $9      
         17        SEND_VAR                                                     $9
         18        INIT_FCALL_BY_NAME                                           'flattenArray'
         19        SEND_VAR_EX                                                  !2
         20        DO_FCALL                                          0  $10     
         21        SEND_VAR                                                     $10
         22        DO_ICALL                                             $11     
         23        ASSIGN                                                       !1, $11
   39    24    > > JMP                                                          ->3
         25    >   FE_FREE                                                      $4
   47    26      > RETURN                                                       !1
   48    27*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iWvnj
function name:  {closure:flattenArray():41}
number of ops:  5
compiled vars:  !0 = $v
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   41     0  E >   RECV                                                 !0      
   42     1        TYPE_CHECK                                      128  ~1      !0
          2        BOOL_NOT                                             ~2      ~1
          3      > RETURN                                                       ~2
   43     4*     > RETURN                                                       null

End of Dynamic Function 0

End of function flattenarray

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.75 ms | 2191 KiB | 17 Q