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]; } } Echo "Json string:\n"; $json = json_encode($result); Var_dump($json); Echo "\n\nback to array: \n"; Var_dump(json_decode($json, true));
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/IEhsp
function name:  (null)
number of ops:  73
compiled vars:  !0 = $array1, !1 = $array2, !2 = $val, !3 = $id, !4 = $name, !5 = $amount, !6 = $result, !7 = $json
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                                         $10     
          6        ASSIGN                                                   !0, $10
    8     7        INIT_FCALL                                               'explode'
          8        SEND_VAL                                                 '%21%21%21'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $12     
         11        ASSIGN                                                   !1, $12
   10    12      > FE_RESET_R                                       $14     !0, ->30
         13    > > FE_FETCH_R                                               $14, !2, ->30
   11    14    >   INIT_FCALL                                               'explode'
         15        SEND_VAL                                                 '%7C'
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                         $15     
         18        FETCH_LIST_R                                     $16     $15, 0
         19        ASSIGN                                                   !3, $16
         20        FETCH_LIST_R                                     $18     $15, 1
         21        ASSIGN                                                   !4, $18
         22        FETCH_LIST_R                                     $20     $15, 2
         23        ASSIGN                                                   !5, $20
         24        FREE                                                     $15
   12    25        INIT_ARRAY                                       ~23     !4, 'name'
         26        ADD_ARRAY_ELEMENT                                ~23     !5, 'amount'
         27        ASSIGN_DIM                                               !6, !3
         28        OP_DATA                                                  ~23
   10    29      > JMP                                                      ->13
         30    >   FE_FREE                                                  $14
   15    31      > FE_RESET_R                                       $24     !1, ->55
         32    > > FE_FETCH_R                                               $24, !2, ->55
   16    33    >   INIT_FCALL                                               'explode'
         34        SEND_VAL                                                 '%7C'
         35        SEND_VAR                                                 !2
         36        DO_ICALL                                         $25     
         37        FETCH_LIST_R                                     $26     $25, 0
         38        ASSIGN                                                   !3, $26
         39        FETCH_LIST_R                                     $28     $25, 1
         40        ASSIGN                                                   !4, $28
         41        FETCH_LIST_R                                     $30     $25, 2
         42        ASSIGN                                                   !5, $30
         43        FREE                                                     $25
   18    44        ISSET_ISEMPTY_DIM_OBJ                         0          !6, !3
         45      > JMPZ                                                     ~32, ->50
   19    46    >   FETCH_DIM_RW                                     $33     !6, !3
         47        ASSIGN_DIM_OP                +=               1          $33, 'amount'
         48        OP_DATA                                                  !5
   18    49      > JMP                                                      ->54
   21    50    >   INIT_ARRAY                                       ~36     !4, 'name'
         51        ADD_ARRAY_ELEMENT                                ~36     !5, 'amount'
         52        ASSIGN_DIM                                               !6, !3
         53        OP_DATA                                                  ~36
   15    54    > > JMP                                                      ->32
         55    >   FE_FREE                                                  $24
   24    56        ECHO                                                     'Json+string%3A%0A'
   25    57        INIT_FCALL                                               'json_encode'
         58        SEND_VAR                                                 !6
         59        DO_ICALL                                         $37     
         60        ASSIGN                                                   !7, $37
   26    61        INIT_FCALL                                               'var_dump'
         62        SEND_VAR                                                 !7
         63        DO_ICALL                                                 
   27    64        ECHO                                                     '%0A%0Aback+to+array%3A+%0A'
   28    65        INIT_FCALL                                               'var_dump'
         66        INIT_FCALL                                               'json_decode'
         67        SEND_VAR                                                 !7
         68        SEND_VAL                                                 <true>
         69        DO_ICALL                                         $40     
         70        SEND_VAR                                                 $40
         71        DO_ICALL                                                 
         72      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.18 ms | 1018 KiB | 17 Q