3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array( array( 'id' => 12, '_from' => 1, '_to' => 2 ), array( 'id' => 13, '_from' => 4, '_to' => 2 ), array( 'id' => 14, '_from' => 2, '_to' => 1 ), ); $newArray = []; foreach ($array as $item) { $uniqueRecordKey = $item['_from'].'-'.$item['_to']; $oppositeRecordKey = $item['_to'].'-'.$item['_from']; //If exists record from the opposite and new ID is greater than previous put if (isset($newArray[$oppositeRecordKey])) { $newArray[$oppositeRecordKey] = $item; continue; //Do not append to the end } $newArray[$uniqueRecordKey] = $item; } var_dump($newArray);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 22
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 22
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/0oL2d
function name:  (null)
number of ops:  27
compiled vars:  !0 = $array, !1 = $newArray, !2 = $item, !3 = $uniqueRecordKey, !4 = $oppositeRecordKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   19     1        ASSIGN                                                   !1, <array>
   20     2      > FE_RESET_R                                       $7      !0, ->22
          3    > > FE_FETCH_R                                               $7, !2, ->22
   21     4    >   FETCH_DIM_R                                      ~8      !2, '_from'
          5        CONCAT                                           ~9      ~8, '-'
          6        FETCH_DIM_R                                      ~10     !2, '_to'
          7        CONCAT                                           ~11     ~9, ~10
          8        ASSIGN                                                   !3, ~11
   22     9        FETCH_DIM_R                                      ~13     !2, '_to'
         10        CONCAT                                           ~14     ~13, '-'
         11        FETCH_DIM_R                                      ~15     !2, '_from'
         12        CONCAT                                           ~16     ~14, ~15
         13        ASSIGN                                                   !4, ~16
   25    14        ISSET_ISEMPTY_DIM_OBJ                         0          !1, !4
         15      > JMPZ                                                     ~18, ->19
   26    16    >   ASSIGN_DIM                                               !1, !4
         17        OP_DATA                                                  !2
   27    18      > JMP                                                      ->3
   30    19    >   ASSIGN_DIM                                               !1, !3
         20        OP_DATA                                                  !2
   20    21      > JMP                                                      ->3
         22    >   FE_FREE                                                  $7
   33    23        INIT_FCALL                                               'var_dump'
         24        SEND_VAR                                                 !1
         25        DO_ICALL                                                 
         26      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.8 ms | 999 KiB | 14 Q