3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr1 = [ ['email' => 'aa@gmail.com', 'name' => 'John Doe'], ['email' => 'bb@gmail.com', 'name' => 'Johnny Sins'], ['email' => 'cc@gmail.com', 'name' => 'Jose Alvarado'], ['email' => 'cc@gmail.com', 'name' => 'Jose Alvarado'] ]; $arr2 = [ ['email' => 'cc@gmail.com', 'country' => 'Japan'], ['email' => 'cc@gmail.com', 'country' => 'China'], ['email' => 'bb@gmail.com', 'country' => 'Korea'], ]; function sanitizeAndKey($array) { $found = []; $clean = []; foreach ($array as $row) { if (isset($found[$row['email']])) { unset($clean[$row['email']]); } else { $found[$row['email']] = $row; $clean[$row['email']] = $row; } } return $clean; } $result = sanitizeAndKey($arr1); foreach (sanitizeAndKey($arr2) as $key => $row) { $result[$key] = ($result[$key] ?? []) + $row; // append arr2 data to arr1 data } var_export(array_values($result));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 19
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 19
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/pRZ5h
function name:  (null)
number of ops:  27
compiled vars:  !0 = $arr1, !1 = $arr2, !2 = $result, !3 = $row, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   30     2        INIT_FCALL                                               'sanitizeandkey'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $7      
          5        ASSIGN                                                   !2, $7
   31     6        INIT_FCALL                                               'sanitizeandkey'
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $9      
          9      > FE_RESET_R                                       $10     $9, ->19
         10    > > FE_FETCH_R                                       ~11     $10, !3, ->19
         11    >   ASSIGN                                                   !4, ~11
   32    12        FETCH_DIM_IS                                     ~14     !2, !4
         13        COALESCE                                         ~15     ~14
         14        QM_ASSIGN                                        ~15     <array>
         15        ADD                                              ~16     ~15, !3
         16        ASSIGN_DIM                                               !2, !4
         17        OP_DATA                                                  ~16
   31    18      > JMP                                                      ->10
         19    >   FE_FREE                                                  $10
   34    20        INIT_FCALL                                               'var_export'
         21        INIT_FCALL                                               'array_values'
         22        SEND_VAR                                                 !2
         23        DO_ICALL                                         $17     
         24        SEND_VAR                                                 $17
         25        DO_ICALL                                                 
         26      > RETURN                                                   1

Function sanitizeandkey:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 18
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 18
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/pRZ5h
function name:  sanitizeAndKey
number of ops:  21
compiled vars:  !0 = $array, !1 = $found, !2 = $clean, !3 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        ASSIGN                                                   !1, <array>
   18     2        ASSIGN                                                   !2, <array>
   19     3      > FE_RESET_R                                       $6      !0, ->18
          4    > > FE_FETCH_R                                               $6, !3, ->18
   20     5    >   FETCH_DIM_R                                      ~7      !3, 'email'
          6        ISSET_ISEMPTY_DIM_OBJ                         0          !1, ~7
          7      > JMPZ                                                     ~8, ->11
   21     8    >   FETCH_DIM_R                                      ~9      !3, 'email'
          9        UNSET_DIM                                                !2, ~9
   20    10      > JMP                                                      ->17
   23    11    >   FETCH_DIM_R                                      ~10     !3, 'email'
         12        ASSIGN_DIM                                               !1, ~10
         13        OP_DATA                                                  !3
   24    14        FETCH_DIM_R                                      ~12     !3, 'email'
         15        ASSIGN_DIM                                               !2, ~12
         16        OP_DATA                                                  !3
   19    17    > > JMP                                                      ->4
         18    >   FE_FREE                                                  $6
   27    19      > RETURN                                                   !2
   28    20*     > RETURN                                                   null

End of function sanitizeandkey

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.11 ms | 1008 KiB | 17 Q