3v4l.org

run code in 300+ PHP versions simultaneously
<?php $inputArray = array( array( array( 'value31', 'value32' ), array( 'value33', 'value34' ), 'value21' ), 'value11' ); function convertArray($inputArray) { if(!checkIfAllArraysExceptLast($inputArray)) return $inputArray; $value = array_pop($inputArray); $result = []; foreach($inputArray as $k => $v){ $result[$k] = is_array($v) ? convertArray($v) : $v; } return [ $value => $result]; } function checkIfAllArraysExceptLast($array){ $v = array_pop($array); return !is_array($v) && count(array_filter($array, fn($v) => is_array($v))) == count($array); } print_r(convertArray($inputArray));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Xbi91
function name:  (null)
number of ops:  8
compiled vars:  !0 = $inputArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   36     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'convertarray'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function convertarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 26
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 26
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/Xbi91
function name:  convertArray
number of ops:  30
compiled vars:  !0 = $inputArray, !1 = $value, !2 = $result, !3 = $v, !4 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        INIT_FCALL_BY_NAME                                       'checkIfAllArraysExceptLast'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $5      
          4        BOOL_NOT                                         ~6      $5
          5      > JMPZ                                                     ~6, ->7
          6    > > RETURN                                                   !0
   21     7    >   INIT_FCALL                                               'array_pop'
          8        SEND_REF                                                 !0
          9        DO_ICALL                                         $7      
         10        ASSIGN                                                   !1, $7
   22    11        ASSIGN                                                   !2, <array>
   24    12      > FE_RESET_R                                       $10     !0, ->26
         13    > > FE_FETCH_R                                       ~11     $10, !3, ->26
         14    >   ASSIGN                                                   !4, ~11
   25    15        TYPE_CHECK                                  128          !3
         16      > JMPZ                                                     ~14, ->22
         17    >   INIT_FCALL_BY_NAME                                       'convertArray'
         18        SEND_VAR_EX                                              !3
         19        DO_FCALL                                      0  $15     
         20        QM_ASSIGN                                        ~16     $15
         21      > JMP                                                      ->23
         22    >   QM_ASSIGN                                        ~16     !3
         23    >   ASSIGN_DIM                                               !2, !4
         24        OP_DATA                                                  ~16
   24    25      > JMP                                                      ->13
         26    >   FE_FREE                                                  $10
   28    27        INIT_ARRAY                                       ~17     !2, !1
         28      > RETURN                                                   ~17
   29    29*     > RETURN                                                   null

End of function convertarray

Function checkifallarraysexceptlast:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/Xbi91
function name:  checkIfAllArraysExceptLast
number of ops:  19
compiled vars:  !0 = $array, !1 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   32     1        INIT_FCALL                                               'array_pop'
          2        SEND_REF                                                 !0
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !1, $2
   33     5        TYPE_CHECK                                  128  ~4      !1
          6        BOOL_NOT                                         ~5      ~4
          7      > JMPZ_EX                                          ~5      ~5, ->17
          8    >   INIT_FCALL                                               'array_filter'
          9        SEND_VAR                                                 !0
         10        DECLARE_LAMBDA_FUNCTION                          ~6      [0]
         11        SEND_VAL                                                 ~6
         12        DO_ICALL                                         $7      
         13        COUNT                                            ~8      $7
         14        COUNT                                            ~9      !0
         15        IS_EQUAL                                         ~10     ~8, ~9
         16        BOOL                                             ~5      ~10
         17    > > RETURN                                                   ~5
   34    18*     > 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/Xbi91
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        TYPE_CHECK                                  128  ~1      !0
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of Dynamic Function 0

End of function checkifallarraysexceptlast

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.03 ms | 1454 KiB | 17 Q