3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = "144|aku|1!!!122|dia|2"; $array2 = "144|aku|1!!!211|dia|1"; $array1 = explode("!!!", $array1); $array2 = explode("!!!", $array2); Foreach($array1 as $val){ List($id, $name, $amount) = explode("|", $val); $result[$id] = ['name' => $name, 'amount' => $amount]; } Foreach($array2 as $val){ List($id, $name, $amount) = explode("|", $val); If(isset($result[$id])){ $result[$id]['amount'] += $amount; }Else{ $result[$id] = ['name' => $name, 'amount' => $amount]; } } Var_dump($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 30
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 30
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 30
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 55
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 55
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 50
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
Branch analysis from position: 30
filename:       /in/gQjTj
function name:  (null)
number of ops:  60
compiled vars:  !0 = $array1, !1 = $array2, !2 = $val, !3 = $id, !4 = $name, !5 = $amount, !6 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '144%7Caku%7C1%21%21%21122%7Cdia%7C2'
    5     1        ASSIGN                                                   !1, '144%7Caku%7C1%21%21%21211%7Cdia%7C1'
    7     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '%21%21%21'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $9      
          6        ASSIGN                                                   !0, $9
    8     7        INIT_FCALL                                               'explode'
          8        SEND_VAL                                                 '%21%21%21'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $11     
         11        ASSIGN                                                   !1, $11
   10    12      > FE_RESET_R                                       $13     !0, ->30
         13    > > FE_FETCH_R                                               $13, !2, ->30
   11    14    >   INIT_FCALL                                               'explode'
         15        SEND_VAL                                                 '%7C'
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                         $14     
         18        FETCH_LIST_R                                     $15     $14, 0
         19        ASSIGN                                                   !3, $15
         20        FETCH_LIST_R                                     $17     $14, 1
         21        ASSIGN                                                   !4, $17
         22        FETCH_LIST_R                                     $19     $14, 2
         23        ASSIGN                                                   !5, $19
         24        FREE                                                     $14
   12    25        INIT_ARRAY                                       ~22     !4, 'name'
         26        ADD_ARRAY_ELEMENT                                ~22     !5, 'amount'
         27        ASSIGN_DIM                                               !6, !3
         28        OP_DATA                                                  ~22
   10    29      > JMP                                                      ->13
         30    >   FE_FREE                                                  $13
   15    31      > FE_RESET_R                                       $23     !1, ->55
         32    > > FE_FETCH_R                                               $23, !2, ->55
   16    33    >   INIT_FCALL                                               'explode'
         34        SEND_VAL                                                 '%7C'
         35        SEND_VAR                                                 !2
         36        DO_ICALL                                         $24     
         37        FETCH_LIST_R                                     $25     $24, 0
         38        ASSIGN                                                   !3, $25
         39        FETCH_LIST_R                                     $27     $24, 1
         40        ASSIGN                                                   !4, $27
         41        FETCH_LIST_R                                     $29     $24, 2
         42        ASSIGN                                                   !5, $29
         43        FREE                                                     $24
   18    44        ISSET_ISEMPTY_DIM_OBJ                         0          !6, !3
         45      > JMPZ                                                     ~31, ->50
   19    46    >   FETCH_DIM_RW                                     $32     !6, !3
         47        ASSIGN_DIM_OP                +=               1          $32, 'amount'
         48        OP_DATA                                                  !5
   18    49      > JMP                                                      ->54
   21    50    >   INIT_ARRAY                                       ~35     !4, 'name'
         51        ADD_ARRAY_ELEMENT                                ~35     !5, 'amount'
         52        ASSIGN_DIM                                               !6, !3
         53        OP_DATA                                                  ~35
   15    54    > > JMP                                                      ->32
         55    >   FE_FREE                                                  $23
   26    56        INIT_FCALL                                               'var_dump'
         57        SEND_VAR                                                 !6
         58        DO_ICALL                                                 
         59      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.14 ms | 1016 KiB | 15 Q