PHP prev

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

PHP: prev() function

PHP: Rewind the internal array pointer

The prev() function is used to fetch the array value in the previous place, pointed by the internal array pointer.

prev() function behaves just like next(), except it rewinds the internal array pointer one place instead of advancing it.

Version

(PHP 4 and above)

Syntax

prev(array_name)

Parameters

Name

Description

Required /
Optional

Type

array_name

The input array.

Required

Array

Return value

The array value of the previous 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 prev() 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. ?>  

Output :

Language
Math
Science
Math