Showing posts with label PHP current. Show all posts
Showing posts with label PHP current. 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

current in PHP

PHP current() function returns the stored value that the present pointer points to.
When array show is recently made with elements, the element pointed to will always be the first element.

Syntax:

current(array)
array : Required. Specifies the array to use.
Tip : This function does not move the arrays internal pointer. To do this, utilize the next() and prev() functions.
Note : This function returns FALSE for empty elements or elements with no value.

Example:

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

Output will be:

Sunday