how to remove start third index from array in auto php code example
Example 1: php array remove after index
$myArrayInit = [1 => 'red', 30 => 'orange', 25 => 'velvet', 45 => 'pink'];
$offsetKey = 25;
$n = array_keys($myArrayInit);
$count = array_search($offsetKey, $n);
$new_arr = array_slice($myArrayInit, 0, $count + 1, true);
print_r($new_arr);
Example 2: php delete element from array
$colors = array("red","blue","green");
unset($colors[1]);
$colors = array("red","blue","green");
array_splice($colors, 1, 1);
Example 3: php erase element from array
foreach ($items as $key =>$item){
if(condition){
unset($item[$key]);
}
}