PHP next

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP: next() function

PHP: Advance the internal array pointer of an array

The next() function is used to advance the internal array pointer. next() behaves like current(), with one difference. It advances the internal array pointer one place forward before returning the element value.

Version

(PHP 4 and above)

Syntax

next(array_name) 

Parameter

Name

Description

Required /
Optional

Type

array_name

The input array.

Required

Array

Return value

The array value in the next place in the array pointed by internal array pointer, or FALSE if there are no more elements.

Value Type : Mixed*.

*Mixed : Mixed indicates multiple (but not necessarily all) types.

Pictorial Presentation :

php array next() function

Example :

  1. $val1 = array('Language', 'Math', 'Science', 'Geography');  

  2. $cval = current($val1);  

  3. echo "$cval 
    ";  

  4. $cval = next($val1);  

  5. echo "$cval 
    ";  

  6. $cval = next($val1);  

  7. echo "$cval 
    ";  

  8. $cval= prev($val1);  

  9. echo "$cval 
    ";  

  10. $cval= end($val1);  

  11. echo "$cval 
    ";  

  12. ?>  

Output :

Language
Math
Science
Math
Geography