Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do mass unset of an array elements in php? [duplicate]

Tags:

arrays

php

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?

like image 968
EbinPaulose Avatar asked Sep 20 '12 06:09

EbinPaulose


1 Answers

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);
like image 56
Jeff Avatar answered Oct 11 '22 22:10

Jeff