3v4l.org

run code in 300+ PHP versions simultaneously
<?php $myarray = [ [ 'messageId' => '5ACE9D8841', 'sender' => 'john@doe.com' ], [ 'messageId' => '7EE67D8170', 'sender' => 'dan@doe.com' ], [ 'messageId' => '8095FD8836', 'sender' => 'cat@doe.com' ], [ 'messageId' => '7EE67D8170', 'dest' => 'mitch@doe.com', 'status' => 'sent', 'date' => '2021-02-01 11:06:55' ] ]; var_export( array_reduce( $myarray, function($result, $row) { static $ref; if (!isset($ref[$row['messageId']])) { $ref[$row['messageId']] = $row; $result[] = &$ref[$row['messageId']]; } else { $ref[$row['messageId']] += $row; } return $result; } ) );
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
array ( 0 => array ( 'messageId' => '5ACE9D8841', 'sender' => 'john@doe.com', ), 1 => array ( 'messageId' => '7EE67D8170', 'sender' => 'dan@doe.com', 'dest' => 'mitch@doe.com', 'status' => 'sent', 'date' => '2021-02-01 11:06:55', ), 2 => array ( 'messageId' => '8095FD8836', 'sender' => 'cat@doe.com', ), )

preferences:
75.33 ms | 403 KiB | 91 Q