3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array ( '2014-04-22|Paul' => 0, '2014-04-28|Paul' => 2, '2014-05-13|Paul' => 0, '2014-06-03|Paul' => 1, '2014-06-12|Paul' => 0, '2014-08-11|Paul' => 1, '2014-08-28|Paul' => 3, '2012-05-09|John' => 1, '2012-08-29|John' => 2, '2012-09-05|John' => 0, '2012-09-13|John' => 1 ); $b = array(); $lastname = ''; foreach ($a as $key => $value) { list($d, $n) = explode('|', $key); if ($n == $lastname) { $total += $value; } else { $total = $value; } $b[$key] = $total; $lastname = $n; } print_r($b);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 24
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 24
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/H0RHT
function name:  (null)
number of ops:  29
compiled vars:  !0 = $a, !1 = $b, !2 = $lastname, !3 = $value, !4 = $key, !5 = $d, !6 = $n, !7 = $total
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   17     1        ASSIGN                                                   !1, <array>
   18     2        ASSIGN                                                   !2, ''
   19     3      > FE_RESET_R                                       $11     !0, ->24
          4    > > FE_FETCH_R                                       ~12     $11, !3, ->24
          5    >   ASSIGN                                                   !4, ~12
   20     6        INIT_FCALL                                               'explode'
          7        SEND_VAL                                                 '%7C'
          8        SEND_VAR                                                 !4
          9        DO_ICALL                                         $14     
         10        FETCH_LIST_R                                     $15     $14, 0
         11        ASSIGN                                                   !5, $15
         12        FETCH_LIST_R                                     $17     $14, 1
         13        ASSIGN                                                   !6, $17
         14        FREE                                                     $14
   21    15        IS_EQUAL                                                 !6, !2
         16      > JMPZ                                                     ~19, ->19
   22    17    >   ASSIGN_OP                                     1          !7, !3
         18      > JMP                                                      ->20
   25    19    >   ASSIGN                                                   !7, !3
   27    20    >   ASSIGN_DIM                                               !1, !4
         21        OP_DATA                                                  !7
   28    22        ASSIGN                                                   !2, !6
   19    23      > JMP                                                      ->4
         24    >   FE_FREE                                                  $11
   30    25        INIT_FCALL                                               'print_r'
         26        SEND_VAR                                                 !1
         27        DO_ICALL                                                 
         28      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.59 ms | 1396 KiB | 17 Q