3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 0 => 'Apple', 2 => 'Orange', 5 => 'Pear', 8 => 'Pear' ]; $result = []; for ( $i = 0, $last = array_key_last($array); $i <= $last; ++$i ) { $result[$i] = $array[$i] ?? null; } var_export($result); echo "\n---\n"; var_export( array_replace( array_fill(0, array_key_last($array), null), $array ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 8
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 8
Branch analysis from position: 16
Branch analysis from position: 8
filename:       /in/mtO3q
function name:  (null)
number of ops:  36
compiled vars:  !0 = $array, !1 = $result, !2 = $i, !3 = $last
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   12     2        ASSIGN                                                   !2, 0
          3        INIT_FCALL                                               'array_key_last'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !3, $7
          7      > JMP                                                      ->14
   16     8    >   FETCH_DIM_IS                                     ~10     !0, !2
          9        COALESCE                                         ~11     ~10
         10        QM_ASSIGN                                        ~11     null
         11        ASSIGN_DIM                                               !1, !2
         12        OP_DATA                                                  ~11
   14    13        PRE_INC                                                  !2
   13    14    >   IS_SMALLER_OR_EQUAL                                      !2, !3
         15      > JMPNZ                                                    ~13, ->8
   18    16    >   INIT_FCALL                                               'var_export'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                                 
   20    19        ECHO                                                     '%0A---%0A'
   22    20        INIT_FCALL                                               'var_export'
   23    21        INIT_FCALL                                               'array_replace'
   24    22        INIT_FCALL                                               'array_fill'
         23        SEND_VAL                                                 0
         24        INIT_FCALL                                               'array_key_last'
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                         $15     
         27        SEND_VAR                                                 $15
         28        SEND_VAL                                                 null
         29        DO_ICALL                                         $16     
         30        SEND_VAR                                                 $16
   25    31        SEND_VAR                                                 !0
   23    32        DO_ICALL                                         $17     
   25    33        SEND_VAR                                                 $17
   22    34        DO_ICALL                                                 
   27    35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.94 ms | 1009 KiB | 17 Q