How can I filter out the array entries with an odd or even index number?
Array ( [0] => string1 [1] => string2 [2] => string3 [3] => string4 )
I want it remove the [0] and [2] entries from the array. Or say I have 0,1,2,3,4,5,6,7,8,9; I would need to remove 0,2,4,6,8.
foreach($arr as $key => $value) if($key&1) unset($arr[$key]);The above removes odd number positions from the array, to remove even number positions, use the following:
Instead
if($key&1)you can useif(!($key&1))