3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [['user1' => 20], ['user2' => 30], 3 => ['user3' => 10]]; echo array_reduce( $array, fn($result, $row) => $result + current($row), 0 ); 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 = 19, Position 2 = 26
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 24
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/4LqbM
function name:  (null)
number of ops:  29
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_reduce'
    5     2        SEND_VAR                                                 !0
    6     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F4LqbM%3A6%240'
          4        SEND_VAL                                                 ~6
    7     5        SEND_VAL                                                 0
          6        DO_ICALL                                         $7      
          7        ECHO                                                     $7
   10     8        ECHO                                                     '%0A---%0A'
   12     9        INIT_FCALL                                               'array_walk_recursive'
         10        SEND_REF                                                 !0
         11        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F4LqbM%3A12%241'
         12        BIND_LEXICAL                                             ~8, !1
         13        SEND_VAL                                                 ~8
         14        DO_ICALL                                                 
   13    15        ECHO                                                     !1
   15    16        ECHO                                                     '%0A---%0A'
   17    17        ASSIGN                                                   !2, 0
   18    18      > FE_RESET_R                                       $11     !0, ->26
         19    > > FE_FETCH_R                                               $11, !3, ->26
   19    20    > > FE_RESET_R                                       $12     !3, ->24
         21    > > FE_FETCH_R                                               $12, !4, ->24
   20    22    >   ASSIGN_OP                                     1          !2, !4
   19    23      > JMP                                                      ->21
         24    >   FE_FREE                                                  $12
   18    25      > JMP                                                      ->19
         26    >   FE_FREE                                                  $11
   23    27        ECHO                                                     !2
   24    28      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F4LqbM%3A6%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4LqbM
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $result, !1 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        INIT_FCALL                                               'current'
          3        SEND_VAR                                                 !1
          4        DO_ICALL                                         $2      
          5        ADD                                              ~3      !0, $2
          6      > RETURN                                                   ~3
          7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F4LqbM%3A6%240

Function %00%7Bclosure%7D%2Fin%2F4LqbM%3A12%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4LqbM
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $v, !1 = $sum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        ASSIGN_OP                                     1          !1, !0
          3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F4LqbM%3A12%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.02 ms | 1411 KiB | 19 Q