3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [['user1' => 20], ['user2' => 30], 3 => ['user3' => 10]]; echo array_sum(array_column(array_map('array_values', $array), 0)); // reindex subarrays, isolate zero column, sum values echo "\n---\n"; array_walk_recursive($array, function($v)use(&$sum){ $sum += $v; }); // visit each leafnode, increase the $sum tally echo $sum; echo "\n---\n"; $total = 0; // without this declaration, you will generate: "Notice: Undefined variable" foreach ($array as $subarray) { foreach ($subarray as $v) { $total += $v; } } echo $total;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 31
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 31
Branch analysis from position: 25
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 29
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 29
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 29
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/l2W0e
function name:  (null)
number of ops:  34
compiled vars:  !0 = $array, !1 = $sum, !2 = $total, !3 = $subarray, !4 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    4     1        INIT_FCALL                                               'array_sum'
          2        INIT_FCALL                                               'array_column'
          3        INIT_FCALL                                               'array_map'
          4        SEND_VAL                                                 'array_values'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $6      
          7        SEND_VAR                                                 $6
          8        SEND_VAL                                                 0
          9        DO_ICALL                                         $7      
         10        SEND_VAR                                                 $7
         11        DO_ICALL                                         $8      
         12        ECHO                                                     $8
    6    13        ECHO                                                     '%0A---%0A'
    8    14        INIT_FCALL                                               'array_walk_recursive'
         15        SEND_REF                                                 !0
         16        DECLARE_LAMBDA_FUNCTION                          ~9      [0]
         17        BIND_LEXICAL                                             ~9, !1
         18        SEND_VAL                                                 ~9
         19        DO_ICALL                                                 
    9    20        ECHO                                                     !1
   11    21        ECHO                                                     '%0A---%0A'
   13    22        ASSIGN                                                   !2, 0
   14    23      > FE_RESET_R                                       $12     !0, ->31
         24    > > FE_FETCH_R                                               $12, !3, ->31
   15    25    > > FE_RESET_R                                       $13     !3, ->29
         26    > > FE_FETCH_R                                               $13, !4, ->29
   16    27    >   ASSIGN_OP                                     1          !2, !4
   15    28      > JMP                                                      ->26
         29    >   FE_FREE                                                  $13
   14    30      > JMP                                                      ->24
         31    >   FE_FREE                                                  $12
   19    32        ECHO                                                     !2
   20    33      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/l2W0e
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $v, !1 = $sum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        ASSIGN_OP                                     1          !1, !0
          3      > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.22 ms | 1008 KiB | 17 Q