3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ 1650 => ["firstName" => "jack", "lastName" => "straw"], 1649 => ["firstName" => "jack", "lastName" => "straw"], 1651 => ["firstName" => "jack", "lastName" => "straw"], 1652 => ["firstName" => "jack", "lastName" => "straw"], 1653 => ["firstName" => "jack1", "lastName" => "straw"], 1654 => ["firstName" => "jack1", "lastName" => "straw"] ]; ksort($array); $temp = []; foreach ($array as $key => $row) { $compositeKey = $row['firstName'] . '-' . $row['firstName']; $temp[$compositeKey] ??= $row; $temp[$compositeKey]['mergedWith'][] = $key; } $result = []; foreach ($temp as $row) { $result[array_shift($row['mergedWith'])] = $row; } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 24
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 24
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 24
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 35
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 35
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
Branch analysis from position: 24
filename:       /in/5KZIi
function name:  (null)
number of ops:  40
compiled vars:  !0 = $array, !1 = $temp, !2 = $row, !3 = $key, !4 = $compositeKey, !5 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   12     1        INIT_FCALL                                                   'ksort'
          2        SEND_REF                                                     !0
          3        DO_ICALL                                                     
   13     4        ASSIGN                                                       !1, <array>
   14     5      > FE_RESET_R                                           $9      !0, ->24
          6    > > FE_FETCH_R                                           ~10     $9, !2, ->24
          7    >   ASSIGN                                                       !3, ~10
   15     8        FETCH_DIM_R                                          ~12     !2, 'firstName'
          9        CONCAT                                               ~13     ~12, '-'
         10        FETCH_DIM_R                                          ~14     !2, 'firstName'
         11        CONCAT                                               ~15     ~13, ~14
         12        ASSIGN                                                       !4, ~15
   16    13        FETCH_DIM_IS                                         ~17     !1, !4
         14        COALESCE                                             ~18     ~17
         15        ASSIGN_DIM                                           ~19     !1, !4
         16        OP_DATA                                                      !2
         17        QM_ASSIGN                                            ~18     ~19
         18        FREE                                                         ~18
   17    19        FETCH_DIM_W                                          $20     !1, !4
         20        FETCH_DIM_W                                          $21     $20, 'mergedWith'
         21        ASSIGN_DIM                                                   $21
         22        OP_DATA                                                      !3
   14    23      > JMP                                                          ->6
         24    >   FE_FREE                                                      $9
   20    25        ASSIGN                                                       !5, <array>
   21    26      > FE_RESET_R                                           $24     !1, ->35
         27    > > FE_FETCH_R                                                   $24, !2, ->35
   22    28    >   INIT_FCALL                                                   'array_shift'
         29        FETCH_DIM_W                                          $25     !2, 'mergedWith'
         30        SEND_REF                                                     $25
         31        DO_ICALL                                             $26     
         32        ASSIGN_DIM                                                   !5, $26
         33        OP_DATA                                                      !2
   21    34      > JMP                                                          ->27
         35    >   FE_FREE                                                      $24
   24    36        INIT_FCALL                                                   'var_export'
         37        SEND_VAR                                                     !5
         38        DO_ICALL                                                     
         39      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
166.19 ms | 1958 KiB | 16 Q