3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( array('city' => 'NewYork', 'cash' => '1000'), array('city' => 'Philadelphia', 'cash' => '2300'), array('city' => 'NewYork', 'cash' => '2000'), ); $newarray = array(); foreach($arr as $ar) { foreach($ar as $k => $v) { if(array_key_exists($v, $newarray)) $newarray[$v]['cash'] = $newarray[$v]['cash'] + $ar['cash']; else if($k == 'city') $newarray[$v] = $ar; } } print_r($newarray);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 24
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 24
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 22
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 22
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 17
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 21
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 22
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/D8PME
function name:  (null)
number of ops:  29
compiled vars:  !0 = $arr, !1 = $newarray, !2 = $ar, !3 = $v, !4 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    9     1        ASSIGN                                                   !1, <array>
   10     2      > FE_RESET_R                                       $7      !0, ->24
          3    > > FE_FETCH_R                                               $7, !2, ->24
   12     4    > > FE_RESET_R                                       $8      !2, ->22
          5    > > FE_FETCH_R                                       ~9      $8, !3, ->22
          6    >   ASSIGN                                                   !4, ~9
   14     7        ARRAY_KEY_EXISTS                                         !3, !1
          8      > JMPZ                                                     ~11, ->17
   15     9    >   FETCH_DIM_R                                      ~14     !1, !3
         10        FETCH_DIM_R                                      ~15     ~14, 'cash'
         11        FETCH_DIM_R                                      ~16     !2, 'cash'
         12        ADD                                              ~17     ~15, ~16
         13        FETCH_DIM_W                                      $12     !1, !3
         14        ASSIGN_DIM                                               $12, 'cash'
         15        OP_DATA                                                  ~17
         16      > JMP                                                      ->21
   16    17    >   IS_EQUAL                                                 !4, 'city'
         18      > JMPZ                                                     ~18, ->21
   17    19    >   ASSIGN_DIM                                               !1, !3
         20        OP_DATA                                                  !2
   12    21    > > JMP                                                      ->5
         22    >   FE_FREE                                                  $8
   10    23      > JMP                                                      ->3
         24    >   FE_FREE                                                  $7
   21    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:
170.87 ms | 941 KiB | 16 Q