3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ 'water' => [0, 1, 2, 3, 4, 5], 'apple' => [1, 5, 3, 4, 0, 0], 'beer' => [0, 0, 0, 0, 0, 0] ]; $arrWeight = array_map(function($value) { return is_array($value) ? array_sum($value) : 0; }, $arr); arsort($arrWeight); $arrAllowedKeys = array_slice($arrWeight, 0, 2, true); $arr = array_intersect_key($arr, $arrAllowedKeys); var_export($arr);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AWPd8
function name:  (null)
number of ops:  26
compiled vars:  !0 = $arr, !1 = $arrWeight, !2 = $arrAllowedKeys
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    9     1        INIT_FCALL                                               'array_map'
          2        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
   11     3        SEND_VAL                                                 ~4
          4        SEND_VAR                                                 !0
    9     5        DO_ICALL                                         $5      
          6        ASSIGN                                                   !1, $5
   13     7        INIT_FCALL                                               'arsort'
          8        SEND_REF                                                 !1
          9        DO_ICALL                                                 
   15    10        INIT_FCALL                                               'array_slice'
         11        SEND_VAR                                                 !1
         12        SEND_VAL                                                 0
         13        SEND_VAL                                                 2
         14        SEND_VAL                                                 <true>
         15        DO_ICALL                                         $8      
         16        ASSIGN                                                   !2, $8
   17    17        INIT_FCALL                                               'array_intersect_key'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !2
         20        DO_ICALL                                         $10     
         21        ASSIGN                                                   !0, $10
   19    22        INIT_FCALL                                               'var_export'
         23        SEND_VAR                                                 !0
         24        DO_ICALL                                                 
         25      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AWPd8
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        TYPE_CHECK                                  128          !0
          2      > JMPZ                                                     ~1, ->8
          3    >   INIT_FCALL                                               'array_sum'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        QM_ASSIGN                                        ~3      $2
          7      > JMP                                                      ->9
          8    >   QM_ASSIGN                                        ~3      0
          9    > > RETURN                                                   ~3
   11    10*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.67 ms | 1008 KiB | 19 Q