Skip / remove the first row of array


Im struggling to skip / remove the first row of results from my array


<?php foreach($this->images AS $image) { 

I tried this but it causes an error. Parse error: syntax error, unexpected T_UNSET in

<?php foreach(unset($this->images[0]) AS $image) { 

Where am I going wrong?

first argument of foreach supposed to be an array
unset function is far from returning array type value

foreach($this->images AS $image) {


foreach($this->images AS $image) {

There’s also array_shift() which returns the first value off the array and removes it from the original array.

$orig_array = array('green', 'blue', 'red');
$discarded_value = array_shift($orig_array);

echo $discarded_value;// green
var_dump($orig_array);// array('blue', 'red');

If you really don’t need the first element anymore after the loop then you can use the witigo’s second method and if you may need this later in the script then you can use the witigo’s first method.

FYI, the unset() function returns nothing since it is a language construct. It just unset the given variable instead (see PHP Manual) whereas the foreach needs the array as the first argument. So always see php manual once you use a function if you are not sure what the function does for you.

Off Topic:

To whom you are asking? Yourself? Are you PHP Programmer?

Thank you guys. Very informative. I only require the first method which works a treat.

Thanks again.