@ 2020-03-09T13:36:05Z <?php
const DATA = [
[1070, 1023, 'this is the first record'],
[1070, 1028, 'this is the second record'],
[1098, 1023, 'this is the thrid record'],
[1098, 1028, 'this is the fourth record'],
[2021, 1023, 'this is the fifth record'],
[2021, 1028, 'this is the sixth record'],
];
function group_records(array $data, int $col)
{
$last = null;
$current = [];
foreach (DATA as $row) {
if ($row[$col] !== $last && $last !== null) {
yield $last => $current;
$last = null;
$current = [];
}
$last = $row[$col];
$current[] = $row;
}
if ($last !== null) {
yield $last => $current;
}
}
foreach (group_records(DATA, 0) as $key => $rows) {
echo "$key:\n";
foreach ($rows as $row) echo " " . implode('|', $row) . "\n";
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.2.0 - 7.2.33 , 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.25 , 8.4.1 - 8.4.12 1070:
1070|1023|this is the first record
1070|1028|this is the second record
1098:
1098|1023|this is the thrid record
1098|1028|this is the fourth record
2021:
2021|1023|this is the fifth record
2021|1028|this is the sixth record
preferences:dark mode live preview ace vim emacs key bindings
132.16 ms | 408 KiB | 5 Q