Possible Duplicate:
unset range of keys in an array
I have an array $test, it contains 1000s of element with random key between 1 and 10000, I want to unset array elements of particular key range. eg i wanna unset elements if the key value between 500 and 600. Now i am using foreach loop to do this. Any other php shortcut to do this?
How about this (untested, hand-written)
function unsetRange($arr,$from,$to)
{
for($i=$from;$i<=$to;$i++)
unset($arr[$i]);
}
// Unset elements from 500 to 600
unsetRange($myArr,500,100);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With