To remove the first n elements from an array:Call the splice method on the array, passing it the start index and the number of elements to remove as arguments. For example, arr. splice(0,2) removes the first two elements from the array and returns a new array containing the removed elements.
shift() The shift() method removes the first element from an array and returns that removed element. This method changes the length of the array.
Use array_slice
:
$output = array_slice($input, 2);
Stop from showing or removing?
for removing:
$array = array();
preg_match( '/src="([^"]*)"/i', $data, $array ) ;
// The following lines will remove values from the first two indexes.
unset($array[0]);
unset($array[1]);
// This line will re-set the indexes (the above just nullifies the values...) and make a new array without the original first two slots.
$array = array_values($array);
// The following line will show the new content of the array
var_dump($array);
Hope this helps!
Use array_slice($array, 2, count($array))
or make your regexp skip the first two if possible.
You could also invoke array_shift() twice on the array. This might be more optimal since it shouldn't need to make a copy of the array.
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