3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr =Array( 0 => Array ( 0 => "string", 1 => 1, "return" => true ), "two" => Array ( 0 => "2017-10-09", 1 => 248.38, "return" => false ), 3 => -123.4, 4 => array( 0 => array( 0 => "foo", 1 => array( 0 => "bar" ) ) ) ); printArray($arr // Input array for output , "array(" // type of output "array()" or "[]" , 1 // start padding multiplied with 4. 1 = 4 spaces indenting at start. , false // is input a subarray. Always false when you call the function. Only function itself should change this ); function printArray($arr, $output, $pad, $subarray){ // If it's a subarray don't indent "array" text if($subarray){ echo str_pad("", 0, " ") . $output ."\n"; }else{ echo str_pad("", $pad*4, " ") . $output ."\n"; } $i=1; foreach($arr as $key => $item){ if(is_array($item)){ echo str_pad("", ($pad+1)*4, " "); // add "" to key if it's associative if(is_string($key)){ echo "\"" . $key. "\" => "; }else{ echo $key . " => "; } // recrusive run printArray with padding +1 (more indenting) printArray($item, $output, $pad+1, true); }else{ echo str_pad("", ($pad+1)*4, " "); // add "" to key if it's associative if(is_string($key)){ echo "\"" . $key. "\""; }else{ echo $key; } // echo item with "" if it's string, or as bool or else as numeric (float/int) if(is_string($item)){ echo " => \"". $item ."\""; }else if(is_bool($item)){ $bool = var_export($item,true); echo " => ". $bool; }else{ echo " => ". $item; } // if it's the last item, don't add comma to end of array if($i == count($arr)){ echo "\n"; }else{ echo ",\n"; } $i++; } } // add correct closing bracket if($output == "["){ echo str_pad("", $pad*4, " ") . "]"; }else{ echo str_pad("", $pad*4, " ") . ")"; } // if it's the very last item add a ; instead of , if($pad == 1){ echo ";\n"; }else{ if($i == count($arr)){ echo "\n"; }else{ echo ",\n"; } } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AOC0L
function name:  (null)
number of ops:  8
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   29     1        INIT_FCALL_BY_NAME                                       'printArray'
          2        SEND_VAR_EX                                              !0
   30     3        SEND_VAL_EX                                              'array%28'
   31     4        SEND_VAL_EX                                              1
   32     5        SEND_VAL_EX                                              <false>
   29     6        DO_FCALL                                      0          
  102     7      > RETURN                                                   1

Function printarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 94
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 94
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 53
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 43
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 93
Branch analysis from position: 93
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 93
Branch analysis from position: 93
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 67
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 74
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 86
Branch analysis from position: 86
2 jumps found. (Code = 43) Position 1 = 89, Position 2 = 91
Branch analysis from position: 89
1 jumps found. (Code = 42) Position 1 = 92
Branch analysis from position: 92
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 91
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 74
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 84
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 86
Branch analysis from position: 86
Branch analysis from position: 84
2 jumps found. (Code = 43) Position 1 = 89, Position 2 = 91
Branch analysis from position: 89
Branch analysis from position: 91
Branch analysis from position: 67
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 74
Branch analysis from position: 70
Branch analysis from position: 74
Branch analysis from position: 94
2 jumps found. (Code = 43) Position 1 = 97, Position 2 = 106
Branch analysis from position: 97
1 jumps found. (Code = 42) Position 1 = 114
Branch analysis from position: 114
2 jumps found. (Code = 43) Position 1 = 116, Position 2 = 118
Branch analysis from position: 116
1 jumps found. (Code = 42) Position 1 = 124
Branch analysis from position: 124
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 118
2 jumps found. (Code = 43) Position 1 = 121, Position 2 = 123
Branch analysis from position: 121
1 jumps found. (Code = 42) Position 1 = 124
Branch analysis from position: 124
Branch analysis from position: 123
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 106
2 jumps found. (Code = 43) Position 1 = 116, Position 2 = 118
Branch analysis from position: 116
Branch analysis from position: 118
Branch analysis from position: 94
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 94
Branch analysis from position: 25
Branch analysis from position: 94
filename:       /in/AOC0L
function name:  printArray
number of ops:  125
compiled vars:  !0 = $arr, !1 = $output, !2 = $pad, !3 = $subarray, !4 = $i, !5 = $item, !6 = $key, !7 = $bool
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   37     4      > JMPZ                                                     !3, ->14
   38     5    >   INIT_FCALL                                               'str_pad'
          6        SEND_VAL                                                 ''
          7        SEND_VAL                                                 0
          8        SEND_VAL                                                 '+'
          9        DO_ICALL                                         $8      
         10        CONCAT                                           ~9      $8, !1
         11        CONCAT                                           ~10     ~9, '%0A'
         12        ECHO                                                     ~10
   37    13      > JMP                                                      ->23
   40    14    >   INIT_FCALL                                               'str_pad'
         15        SEND_VAL                                                 ''
         16        MUL                                              ~11     !2, 4
         17        SEND_VAL                                                 ~11
         18        SEND_VAL                                                 '+'
         19        DO_ICALL                                         $12     
         20        CONCAT                                           ~13     $12, !1
         21        CONCAT                                           ~14     ~13, '%0A'
         22        ECHO                                                     ~14
   43    23    >   ASSIGN                                                   !4, 1
   44    24      > FE_RESET_R                                       $16     !0, ->94
         25    > > FE_FETCH_R                                       ~17     $16, !5, ->94
         26    >   ASSIGN                                                   !6, ~17
   45    27        TYPE_CHECK                                  128          !5
         28      > JMPZ                                                     ~19, ->53
   46    29    >   INIT_FCALL                                               'str_pad'
         30        SEND_VAL                                                 ''
         31        ADD                                              ~20     !2, 1
         32        MUL                                              ~21     ~20, 4
         33        SEND_VAL                                                 ~21
         34        SEND_VAL                                                 '+'
         35        DO_ICALL                                         $22     
         36        ECHO                                                     $22
   48    37        TYPE_CHECK                                   64          !6
         38      > JMPZ                                                     ~23, ->43
   49    39    >   CONCAT                                           ~24     '%22', !6
         40        CONCAT                                           ~25     ~24, '%22+%3D%3E+'
         41        ECHO                                                     ~25
   48    42      > JMP                                                      ->45
   51    43    >   CONCAT                                           ~26     !6, '+%3D%3E+'
         44        ECHO                                                     ~26
   54    45    >   INIT_FCALL_BY_NAME                                       'printArray'
         46        SEND_VAR_EX                                              !5
         47        SEND_VAR_EX                                              !1
         48        ADD                                              ~27     !2, 1
         49        SEND_VAL_EX                                              ~27
         50        SEND_VAL_EX                                              <true>
         51        DO_FCALL                                      0          
   45    52      > JMP                                                      ->93
   56    53    >   INIT_FCALL                                               'str_pad'
         54        SEND_VAL                                                 ''
         55        ADD                                              ~29     !2, 1
         56        MUL                                              ~30     ~29, 4
         57        SEND_VAL                                                 ~30
         58        SEND_VAL                                                 '+'
         59        DO_ICALL                                         $31     
         60        ECHO                                                     $31
   59    61        TYPE_CHECK                                   64          !6
         62      > JMPZ                                                     ~32, ->67
   60    63    >   CONCAT                                           ~33     '%22', !6
         64        CONCAT                                           ~34     ~33, '%22'
         65        ECHO                                                     ~34
   59    66      > JMP                                                      ->68
   62    67    >   ECHO                                                     !6
   66    68    >   TYPE_CHECK                                   64          !5
         69      > JMPZ                                                     ~35, ->74
   67    70    >   CONCAT                                           ~36     '+%3D%3E+%22', !5
         71        CONCAT                                           ~37     ~36, '%22'
         72        ECHO                                                     ~37
   66    73      > JMP                                                      ->86
   68    74    >   TYPE_CHECK                                   12          !5
         75      > JMPZ                                                     ~38, ->84
   69    76    >   INIT_FCALL                                               'var_export'
         77        SEND_VAR                                                 !5
         78        SEND_VAL                                                 <true>
         79        DO_ICALL                                         $39     
         80        ASSIGN                                                   !7, $39
   70    81        CONCAT                                           ~41     '+%3D%3E+', !7
         82        ECHO                                                     ~41
   68    83      > JMP                                                      ->86
   72    84    >   CONCAT                                           ~42     '+%3D%3E+', !5
         85        ECHO                                                     ~42
   76    86    >   COUNT                                            ~43     !0
         87        IS_EQUAL                                                 !4, ~43
         88      > JMPZ                                                     ~44, ->91
   77    89    >   ECHO                                                     '%0A'
   76    90      > JMP                                                      ->92
   79    91    >   ECHO                                                     '%2C%0A'
   81    92    >   PRE_INC                                                  !4
   44    93    > > JMP                                                      ->25
         94    >   FE_FREE                                                  $16
   86    95        IS_EQUAL                                                 !1, '%5B'
         96      > JMPZ                                                     ~46, ->106
   87    97    >   INIT_FCALL                                               'str_pad'
         98        SEND_VAL                                                 ''
         99        MUL                                              ~47     !2, 4
        100        SEND_VAL                                                 ~47
        101        SEND_VAL                                                 '+'
        102        DO_ICALL                                         $48     
        103        CONCAT                                           ~49     $48, '%5D'
        104        ECHO                                                     ~49
   86   105      > JMP                                                      ->114
   89   106    >   INIT_FCALL                                               'str_pad'
        107        SEND_VAL                                                 ''
        108        MUL                                              ~50     !2, 4
        109        SEND_VAL                                                 ~50
        110        SEND_VAL                                                 '+'
        111        DO_ICALL                                         $51     
        112        CONCAT                                           ~52     $51, '%29'
        113        ECHO                                                     ~52
   93   114    >   IS_EQUAL                                                 !2, 1
        115      > JMPZ                                                     ~53, ->118
   94   116    >   ECHO                                                     '%3B%0A'
   93   117      > JMP                                                      ->124
   96   118    >   COUNT                                            ~54     !0
        119        IS_EQUAL                                                 !4, ~54
        120      > JMPZ                                                     ~55, ->123
   97   121    >   ECHO                                                     '%0A'
   96   122      > JMP                                                      ->124
   99   123    >   ECHO                                                     '%2C%0A'
  102   124    > > RETURN                                                   null

End of function printarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.57 ms | 1024 KiB | 15 Q