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 } $unique = usort($unique, "cmp"); print_r($unique); foreach ($unique as $key => $value) { $array[$value['id']] = $value; } echo '<pre>'; print_r($array); function cmp($a, $b) { return $a["call-id"] - $b["call-id"]; }
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 = 18, Position 2 = 24
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 24
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
Branch analysis from position: 8
filename:       /in/blfIJ
function name:  (null)
number of ops:  30
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
   38     9        INIT_FCALL                                               'usort'
         10        SEND_REF                                                 !3
         11        SEND_VAL                                                 'cmp'
         12        DO_ICALL                                         $12     
         13        ASSIGN                                                   !3, $12
   39    14        INIT_FCALL                                               'print_r'
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                                 
   40    17      > FE_RESET_R                                       $15     !3, ->24
         18    > > FE_FETCH_R                                       ~16     $15, !1, ->24
         19    >   ASSIGN                                                   !4, ~16
   41    20        FETCH_DIM_R                                      ~18     !1, 'id'
         21        ASSIGN_DIM                                               !5, ~18
         22        OP_DATA                                                  !1
   40    23      > JMP                                                      ->18
         24    >   FE_FREE                                                  $15
   44    25        ECHO                                                     '%3Cpre%3E'
   45    26        INIT_FCALL                                               'print_r'
         27        SEND_VAR                                                 !5
         28        DO_ICALL                                                 
   50    29      > RETURN                                                   1

Function cmp:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/blfIJ
function name:  cmp
number of ops:  7
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   49     2        FETCH_DIM_R                                      ~2      !0, 'call-id'
          3        FETCH_DIM_R                                      ~3      !1, 'call-id'
          4        SUB                                              ~4      ~2, ~3
          5      > RETURN                                                   ~4
   50     6*     > RETURN                                                   null

End of function cmp

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.94 ms | 1400 KiB | 17 Q