Showing posts with label PHP next. Show all posts
Showing posts with label PHP next. Show all posts

Thursday, 25 September 2014

prev in PHP

PHP prev() function is used to move internal pointer of an array to previous element, and returns it.
PHP prev() function returns value of previous element from array on success, or else FALSE if there are no more elements.

Syntax:


prev(array)
array : Required. Specifies the array to use.

Example:


<?php
$daysarr = array( "Sunday","Monday","Tuesday","Wednesday","Thursday" );
echo current($daysarr) . " < br />";
echo next($daysarr) . " < br />";
echo prev($daysarr);
?>

Output will be:


Sunday
Monday
Sunday

next in PHP

PHP next() function is utilized to move internal pointer of an array to next element and returns it.
This function returns value of next element from array on success, or else FALSE if there are no more elements.

Syntax:

next(array)
array : Required. Specifies the array to use.
Note : PHP next() function returns FALSE on empty elements or elements with no value.

Example:

<?php
$daysarr = array( "Sunday","Monday","Tuesday","Wednesday","Thursday" );
echo current($daysarr) . "<br />";
echo next($daysarr);
?>

O/P:

Sunday
Monday