3v4l.org

run code in 300+ PHP versions simultaneously
<?php $levels = [1=>10, 2=>20, 3=>30, 6=>60]; $a = array_keys($levels); sort($a); $max = end($a); $toAdd = array_diff(array_keys(array_fill(1, $max, 0)), $a); $result = array_fill_keys($toAdd, 0); $merged = $levels + $result; krsort($merged); var_dump($result); var_dump($merged);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6o1Uf
function name:  (null)
number of ops:  42
compiled vars:  !0 = $levels, !1 = $a, !2 = $max, !3 = $toAdd, !4 = $result, !5 = $merged
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        INIT_FCALL                                               'array_keys'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $7      
          4        ASSIGN                                                   !1, $7
    6     5        INIT_FCALL                                               'sort'
          6        SEND_REF                                                 !1
          7        DO_ICALL                                                 
    7     8        INIT_FCALL                                               'end'
          9        SEND_REF                                                 !1
         10        DO_ICALL                                         $10     
         11        ASSIGN                                                   !2, $10
    8    12        INIT_FCALL                                               'array_diff'
         13        INIT_FCALL                                               'array_keys'
         14        INIT_FCALL                                               'array_fill'
         15        SEND_VAL                                                 1
         16        SEND_VAR                                                 !2
         17        SEND_VAL                                                 0
         18        DO_ICALL                                         $12     
         19        SEND_VAR                                                 $12
         20        DO_ICALL                                         $13     
         21        SEND_VAR                                                 $13
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                         $14     
         24        ASSIGN                                                   !3, $14
   10    25        INIT_FCALL                                               'array_fill_keys'
         26        SEND_VAR                                                 !3
         27        SEND_VAL                                                 0
         28        DO_ICALL                                         $16     
         29        ASSIGN                                                   !4, $16
   11    30        ADD                                              ~18     !0, !4
         31        ASSIGN                                                   !5, ~18
   12    32        INIT_FCALL                                               'krsort'
         33        SEND_REF                                                 !5
         34        DO_ICALL                                                 
   14    35        INIT_FCALL                                               'var_dump'
         36        SEND_VAR                                                 !4
         37        DO_ICALL                                                 
   15    38        INIT_FCALL                                               'var_dump'
         39        SEND_VAR                                                 !5
         40        DO_ICALL                                                 
         41      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
184.38 ms | 1396 KiB | 29 Q