<?php
$array = array(
0 => 'Value1',
1 => 'Value2',
2 => 'Remove',
3 => 'Value3',
4 => 'Value4',
5 => 'Dont remove',
6 => 'Value5',
7 => 'Value6',
8 => 'Remove'
);
foreach ($array as $k=>$v) {
if ($v == 'Remove') {
unset($array[$k]);
unset($array[$k-1]);
unset($array[$k-2]);
}
}
print_r($array);
- Output for 7.1.25 - 7.1.30, 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.26, 8.4.1 - 8.4.13
- Array
(
[3] => Value3
[4] => Value4
[5] => Dont remove
)
preferences:
153.83 ms | 407 KiB | 5 Q