I have an array that is in a certain order and I want to just cutoff a portion of the array starting from the first index to the index of a given key.
IE... If i had this array
$array = array("0" => 'blue', "1" => 'red', "2" => 'green', "3" => 'red', "4"=>"purple");
I want to cut off the first part of the array before the key "2" (as a string) is seen. So the end array would be something like...
"2" => 'green'
"3" => 'red'
"4"=>'purple'
Thanks, Ian
For your case you can use
print_r(array_slice($array, 2, count($array),true));
EDIT: For edited question
$cloneArray = $array;
foreach($array as $key => $value){
if($key == $givenInex)
break;
unset($cloneArray[$key]);
}
Then use $cloneArray
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