3v4l.org

run code in 300+ PHP versions simultaneously
<?php $messages = array( 'message1'=>array( 'type'=>'voice', 'call-id'=>'11', 'id'=>'message1' ), 'message2'=>array( 'type'=>'voice', 'call-id'=>'44', 'id'=>'message2' ), 'message3'=>array( 'type'=>'text', 'call-id'=>'44', 'id'=>'message3' ), 'message4'=>array( 'type'=>'text', 'call-id'=>'55', 'id'=>'message4' ), 'message5'=>array( 'type'=>'voice', 'call-id'=>'55', 'id'=>'message5' ), ); foreach ($messages as $message => $value) { $unique[$value['call-id']] = $value; // this will override the previous value with the same key if exists } print_r($unique); foreach ($unique as $key => $value) { $array[$value['id']] = $value; } echo '<pre>'; print_r($array);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 8
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 19
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
Branch analysis from position: 8
filename:       /in/2Md6s
function name:  (null)
number of ops:  25
compiled vars:  !0 = $messages, !1 = $value, !2 = $message, !3 = $unique, !4 = $key, !5 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   32     1      > FE_RESET_R                                       $7      !0, ->8
          2    > > FE_FETCH_R                                       ~8      $7, !1, ->8
          3    >   ASSIGN                                                   !2, ~8
   33     4        FETCH_DIM_R                                      ~10     !1, 'call-id'
          5        ASSIGN_DIM                                               !3, ~10
          6        OP_DATA                                                  !1
   32     7      > JMP                                                      ->2
          8    >   FE_FREE                                                  $7
   37     9        INIT_FCALL                                               'print_r'
         10        SEND_VAR                                                 !3
         11        DO_ICALL                                                 
   38    12      > FE_RESET_R                                       $13     !3, ->19
         13    > > FE_FETCH_R                                       ~14     $13, !1, ->19
         14    >   ASSIGN                                                   !4, ~14
   39    15        FETCH_DIM_R                                      ~16     !1, 'id'
         16        ASSIGN_DIM                                               !5, ~16
         17        OP_DATA                                                  !1
   38    18      > JMP                                                      ->13
         19    >   FE_FREE                                                  $13
   42    20        ECHO                                                     '%3Cpre%3E'
   43    21        INIT_FCALL                                               'print_r'
         22        SEND_VAR                                                 !5
         23        DO_ICALL                                                 
         24      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.98 ms | 1400 KiB | 15 Q