3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); $data = [ '-MC1kTfrrDHY3ZbidJ4Q' => [ 'from' => 'lSUfZ4sgEJd', 'message' => 'test message four no more!', 'startedAt' => '2020-07-12 11:21:10', 'to' => 'CWgPqdn3YweN', ], '-MC09BsjtXP0izITsThf' => [ 'from' => 'CWgPqdn3YweN', 'message' => 'test message three', 'startedAt' => '2020-07-11 11:20:19', 'subject' => '-MC00BHCZlXUp25C5nlS', 'to' => 'lSUfZ4sgEJd', ], '-MC1kAi1niswXtjY_h4s' => [ 'from' => 'CWgPqdn3YweN', 'message' => 'test message two', 'startedAt' => '2020-07-12 11:19:52', 'to' => 'lSUfZ4sgEJd', ], '-MC1kOtfnIlAYtmJsD-a' => [ 'from' => 'CWgPqdn3YweN', 'message' => 'test message one', 'startedAt' => '2020-07-12 11:18:50', 'to' => 'lSUfZ4sgEJd', ], '-MC1kOtfnIlAhgcufu' => [ 'from' => 'CWgPqdn3YweN', 'message' => 'test message zero', 'startedAt' => '2020-07-12 11:00:50', 'to' => 'YLisXjk07w93', ], ]; function getLatestUniqueConversationMessagesByUser(array $message, string $user): array { $conversations = []; $latestUniqueConversationMessages = []; foreach ($message as $messageKey => $message) { $participants = [$message['from'], $message['to']]; // Skip entries where $user is has not participated (not sure if needed) if (!in_array($user, $participants)) { continue; } // Make "to|from" same as "from|to" sort($participants); $conversationKey = join('|', $participants); // Check if conversation has been handled already if (!array_key_exists($conversationKey, $conversations)) { $conversations[$conversationKey] = true; // Save as "handled" $latestUniqueConversationMessages[$messageKey] = $message; // Save actual data to return } } return $latestUniqueConversationMessages; } var_dump(getLatestUniqueConversationMessagesByUser($data, 'CWgPqdn3YweN'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/msUPQ
function name:  (null)
number of ops:  9
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                   !0, <array>
   64     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'getlatestuniqueconversationmessagesbyuser'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'CWgPqdn3YweN'
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function getlatestuniqueconversationmessagesbyuser:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 35
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 35
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 19
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 34
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 34
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/msUPQ
function name:  getLatestUniqueConversationMessagesByUser
number of ops:  40
compiled vars:  !0 = $message, !1 = $user, !2 = $conversations, !3 = $latestUniqueConversationMessages, !4 = $messageKey, !5 = $participants, !6 = $conversationKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   41     2        ASSIGN                                                   !2, <array>
   42     3        ASSIGN                                                   !3, <array>
   44     4      > FE_RESET_R                                       $9      !0, ->35
          5    > > FE_FETCH_R                                       ~10     $9, !0, ->35
          6    >   ASSIGN                                                   !4, ~10
   45     7        FETCH_DIM_R                                      ~12     !0, 'from'
          8        INIT_ARRAY                                       ~13     ~12
          9        FETCH_DIM_R                                      ~14     !0, 'to'
         10        ADD_ARRAY_ELEMENT                                ~13     ~14
         11        ASSIGN                                                   !5, ~13
   48    12        INIT_FCALL                                               'in_array'
         13        SEND_VAR                                                 !1
         14        SEND_VAR                                                 !5
         15        DO_ICALL                                         $16     
         16        BOOL_NOT                                         ~17     $16
         17      > JMPZ                                                     ~17, ->19
         18    > > JMP                                                      ->5
   51    19    >   INIT_FCALL                                               'sort'
         20        SEND_REF                                                 !5
         21        DO_ICALL                                                 
   52    22        INIT_FCALL                                               'join'
         23        SEND_VAL                                                 '%7C'
         24        SEND_VAR                                                 !5
         25        DO_ICALL                                         $19     
         26        ASSIGN                                                   !6, $19
   55    27        ARRAY_KEY_EXISTS                                 ~21     !6, !2
         28        BOOL_NOT                                         ~22     ~21
         29      > JMPZ                                                     ~22, ->34
   56    30    >   ASSIGN_DIM                                               !2, !6
         31        OP_DATA                                                  <true>
   57    32        ASSIGN_DIM                                               !3, !4
         33        OP_DATA                                                  !0
   44    34    > > JMP                                                      ->5
         35    >   FE_FREE                                                  $9
   61    36        VERIFY_RETURN_TYPE                                       !3
         37      > RETURN                                                   !3
   62    38*       VERIFY_RETURN_TYPE                                       
         39*     > RETURN                                                   null

End of function getlatestuniqueconversationmessagesbyuser

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.35 ms | 1016 KiB | 18 Q