3v4l.org

run code in 500+ PHP versions simultaneously
<?php $movements = [ ['id' => 90415, 'oldDate' => '2024-08-27', 'newDate' => '2024-08-28'], ['id' => 90415, 'oldDate' => '2024-08-28', 'newDate' => '2024-08-27'], ['id' => 90409, 'oldDate' => '2024-08-21', 'newDate' => '2024-08-22'], ['id' => 90409, 'oldDate' => '2024-08-22', 'newDate' => '2024-08-23'], ]; var_export( array_values( array_filter( array_reduce( $movements, function($carry, $move) { $carry[$move['id']] ??= $move; $carry[$move['id']]['newDate'] = $move['newDate']; return $carry; } ), fn($move) => $move['oldDate'] != $move['newDate'] ) ) );
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
array ( 0 => array ( 'id' => 90409, 'oldDate' => '2024-08-21', 'newDate' => '2024-08-23', ), )

preferences:
68.2 ms | 988 KiB | 4 Q