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);
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
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 ) )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
180.38 ms | 408 KiB | 5 Q