This is only for arrays with index number. For example i have this arrays;
$array = [
"0" => "number 1",
"1" => "number 2",
"2" => "number 3",
"3" => "number 4",
"4" => "number 5",
"5" => "number 6",
"6" => "number 7",
"7" => "number 8",
"8" => "number 9"
];
I want to skip the loop from certain range of key indexes for example, skip the foreach if the number of index is from range 0 to 5. That means we can do just like this.
foreach($array as $key => $value){
if(array_key_exist($key, range(0,5))
continue;
echo $value."<br/>"
}
or we can using for... loop
for($ind = 0; $ind < count($array); $ind++){
if(array_key_exist($ind, range(0,5))
continue;
echo $arr[$ind]."<br/>"
}
How could i skip the index without using continue or searching the array_key first ? sure the code above looks fine to me, but if i have a bunch of arrays keys and values, i think this is not a good choice.
forloop at 6?for($ind = 6; $ind < count($array); $ind++){then you don't need a check in the loop at all.array_key_existswould be pretty inefficient. It would be faster to just useif ($ind >= 0 && $ind <= 5) continue;. But... without seeing the true complexity of what you are trying to do (you mention "a bunch of arrays keys and values") it's hard to offer a good solution.array_diffand then loop on that output?print_r(array_diff_key($array, array_flip(range(3,5))));