3v4l.org

run code in 300+ PHP versions simultaneously
<?php $myarray = array( [ 'messageId' => '5ACE9D8841', 'sender' => 'john@doe.com', ], [ 'messageId' => '7EE67D8170', 'sender' => 'dan@doe.com', ], [ 'messageId' => '8095FD8836', 'sender' => 'cat@doe.com', ], [ 'messageId' => ['brokenId' => '8095FD8836'], 'sender' => 'cat@doe.com', ], [ 'status' => 'wrong row', ], [ 'messageId' => '7EE67D8170', 'dest' => 'mitch@doe.com', 'status' => 'sent', 'date' => '2021-02-01 11:06:55', ], ); $result = array_reduce($myarray, function($rows, $item){ if (array_key_exists('messageId', $item) && is_scalar($item['messageId'])) { $rows = array_replace_recursive($rows ?? [], [$item['messageId'] => $item]); } return $rows; }); $result = array_values($result); print_r($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TXJjt
function name:  (null)
number of ops:  15
compiled vars:  !0 = $myarray, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   32     1        INIT_FCALL                                               'array_reduce'
          2        SEND_VAR                                                 !0
          3        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
   37     4        SEND_VAL                                                 ~3
   32     5        DO_ICALL                                         $4      
          6        ASSIGN                                                   !1, $4
   39     7        INIT_FCALL                                               'array_values'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $6      
         10        ASSIGN                                                   !1, $6
   41    11        INIT_FCALL                                               'print_r'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                                 
         14      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
Branch analysis from position: 7
filename:       /in/TXJjt
function name:  {closure}
number of ops:  19
compiled vars:  !0 = $rows, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   33     2        ARRAY_KEY_EXISTS                                 ~2      'messageId', !1
          3      > JMPZ_EX                                          ~2      ~2, ->7
          4    >   FETCH_DIM_R                                      ~3      !1, 'messageId'
          5        TYPE_CHECK                                  124  ~4      ~3
          6        BOOL                                             ~2      ~4
          7    > > JMPZ                                                     ~2, ->17
   34     8    >   INIT_FCALL                                               'array_replace_recursive'
          9        COALESCE                                         ~5      !0
         10        QM_ASSIGN                                        ~5      <array>
         11        SEND_VAL                                                 ~5
         12        FETCH_DIM_R                                      ~6      !1, 'messageId'
         13        INIT_ARRAY                                       ~7      !1, ~6
         14        SEND_VAL                                                 ~7
         15        DO_ICALL                                         $8      
         16        ASSIGN                                                   !0, $8
   36    17    > > RETURN                                                   !0
   37    18*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.43 ms | 1006 KiB | 17 Q