<?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);
preferences:
27.35 ms | 405 KiB | 5 Q