3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Flatten a multi-dimensional array to a single-level array, * sorting the entries in order to depth first. * * @param array $carry Optional Array to initialize * @param mixed $subject Array or value that has data in potential multi-dimensions. * * @return array */ function array_flatten(?array $carry = [], $subject): array { return array_reduce((array) $subject, function(array $carry, $item) { return is_array($item) ? array_flatten($carry, $item) : array_merge($carry, (array) $item); }, (array) $carry); } print_r(array_flatten(null, array( array('A', array('B', array('CC','CCCC','CCCCCC'), array('DDD','EFG','HIJ','LMNOP') ) ), array('2'), 'b', array(array(),array(),array()), ))); $array = array(1,2,[3,4],5,'six',array(array('78',9)),10); print_r(array_reduce($array, "array_flatten"));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/J1NeJ
function name:  (null)
number of ops:  16
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   INIT_FCALL                                               'print_r'
          1        INIT_FCALL                                               'array_flatten'
          2        SEND_VAL                                                 null
   22     3        SEND_VAL                                                 <array>
          4        DO_FCALL                                      0  $1      
          5        SEND_VAR                                                 $1
          6        DO_ICALL                                                 
   33     7        ASSIGN                                                   !0, <array>
   35     8        INIT_FCALL                                               'print_r'
          9        INIT_FCALL                                               'array_reduce'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 'array_flatten'
         12        DO_ICALL                                         $4      
         13        SEND_VAR                                                 $4
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

Function array_flatten:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/J1NeJ
function name:  array_flatten
number of ops:  14
compiled vars:  !0 = $carry, !1 = $subject
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV_INIT                                        !0      <array>
          1        RECV                                             !1      
   14     2        INIT_FCALL                                               'array_reduce'
          3        CAST                                          7  ~2      !1
          4        SEND_VAL                                                 ~2
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FJ1NeJ%3A14%240'
   18     6        SEND_VAL                                                 ~3
          7        CAST                                          7  ~4      !0
          8        SEND_VAL                                                 ~4
          9        DO_ICALL                                         $5      
         10        VERIFY_RETURN_TYPE                                       $5
         11      > RETURN                                                   $5
   19    12*       VERIFY_RETURN_TYPE                                       
         13*     > RETURN                                                   null

End of function array_flatten

Function %00%7Bclosure%7D%2Fin%2FJ1NeJ%3A14%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/J1NeJ
function name:  {closure}
number of ops:  18
compiled vars:  !0 = $carry, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2        TYPE_CHECK                                  128          !1
          3      > JMPZ                                                     ~2, ->10
   16     4    >   INIT_FCALL_BY_NAME                                       'array_flatten'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $3      
          8        QM_ASSIGN                                        ~4      $3
          9      > JMP                                                      ->16
   17    10    >   INIT_FCALL                                               'array_merge'
         11        SEND_VAR                                                 !0
         12        CAST                                          7  ~5      !1
         13        SEND_VAL                                                 ~5
         14        DO_ICALL                                         $6      
         15        QM_ASSIGN                                        ~4      $6
         16    > > RETURN                                                   ~4
   18    17*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FJ1NeJ%3A14%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.4 ms | 1403 KiB | 20 Q