You should use a prefix test using [isset][1] method. The call would look like that: if (isset($items[ $count + 1 ])) { //do stuffs} [1]: http://php.net/manual/fr/function.isset.php