prev() function in PHP || PHP Prev Function

prev() function in php

Last Updated by Pooja Chikara 25-Apr-20

0 371


PHP prev() function is used to move the current pointer of an array to the previous position and return the value on that position. It is an inbuilt function of PHP.

Syntax:

prev($array);

here,

$array is a PHP array.


Example:

<?php
$arr1 = array("apple","orange","banana","fig",);
$next_value=next($arr1); // it returns value on next position from current pointer i.e. orange
$previous_value=prev($arr1); // it will return value on previous position from current pointer i.e. apple
echo "Next value is $next_value <br>";
echo "Previous value is $previous_value";
?>

Output:

prev() function in php

Note: You should also read current(), next(), end() and reset() functions.


Share:


Leave a Reply


Comments
    Waiting for your comments