3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['action' => 'Created', 'timestamp' => '2023-10-30 20:51:57.284602'], ['action' => 'Updated', 'timestamp' => '2023-10-30 20:51:57.284603'], ['action' => 'Started', 'timestamp' => '2023-10-30 20:51:57.284604'], ['action' => 'Bid placed', 'timestamp' => '2023-10-30 20:51:57.284605'], ['action' => 'Bid placed', 'timestamp' => '2023-10-30 20:51:57.284606'], ['action' => 'Max bid placed', 'timestamp' => '2023-10-30 20:51:57.284607'], ['action' => 'Bid placed', 'timestamp' => '2023-10-30 20:51:57.284608'], ['action' => 'Had a nap', 'timestamp' => '2023-10-30 20:51:57.284609'], //['action' => 'Max bid placed', 'timestamp' => '2023-10-30 20:51:57.284610'], ['action' => 'Bid placed', 'timestamp' => '2023-10-30 20:51:57.284611'], ['action' => 'Max bid placed', 'timestamp' => '2023-10-30 20:51:57.284612'], ['action' => 'Ended', 'timestamp' => '2023-10-30 20:51:57.284613'], ]; $start = null; foreach ($array as $i => $row) { if ($row['action'] === 'Bid placed') { $start ??= $i; // only store the first $i in the group continue; } if ($start !== null && $row['action'] === 'Max bid placed') { array_splice($array, $start, 0, array_splice($array, $i, 1)); // prune and reinsert row } $start = null; } var_export($array);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.13
array ( 0 => array ( 'action' => 'Created', 'timestamp' => '2023-10-30 20:51:57.284602', ), 1 => array ( 'action' => 'Updated', 'timestamp' => '2023-10-30 20:51:57.284603', ), 2 => array ( 'action' => 'Started', 'timestamp' => '2023-10-30 20:51:57.284604', ), 3 => array ( 'action' => 'Max bid placed', 'timestamp' => '2023-10-30 20:51:57.284607', ), 4 => array ( 'action' => 'Bid placed', 'timestamp' => '2023-10-30 20:51:57.284605', ), 5 => array ( 'action' => 'Bid placed', 'timestamp' => '2023-10-30 20:51:57.284606', ), 6 => array ( 'action' => 'Bid placed', 'timestamp' => '2023-10-30 20:51:57.284608', ), 7 => array ( 'action' => 'Had a nap', 'timestamp' => '2023-10-30 20:51:57.284609', ), 8 => array ( 'action' => 'Max bid placed', 'timestamp' => '2023-10-30 20:51:57.284612', ), 9 => array ( 'action' => 'Bid placed', 'timestamp' => '2023-10-30 20:51:57.284611', ), 10 => array ( 'action' => 'Ended', 'timestamp' => '2023-10-30 20:51:57.284613', ), )

preferences:
72.94 ms | 410 KiB | 5 Q