PHP prev() Function Last Updated : 20 Jun, 2023 Comments Improve Suggest changes Like Article Like Report The prev() function is an inbuilt function in PHP. It is used to return the immediate previous element from an array of the element which is currently pointed by the internal pointer. We have already discussed current() function in PHP. The current() function is used to return the value of the element which is currently pointed by the internal pointer whereas the prev() function decrements or make the internal pointer to point to the previous element of the currently pointed element. Syntax: prev($array) Parameters: This function accepts a single parameter $array. It is the array of which we want to find the current element. Return Value: It returns the value of the element in the array which is just before the element which the internal pointer is currently pointing to. If the array is empty then the prev() function returns FALSE. Below programs illustrate the prev() function in PHP: Program 1: PHP <?php // input array $arr = array("Ram", "Shita", "Geeta", "Shyam"); // current function print the // 1st element of the array. echo current($arr) ."\n"; // next function prints the next // element of the current one. echo next($arr)."\n"; // prev function will print the previous element // of the current one. As right now current element // is Shita so the previous element will be Ram echo prev($arr); ?> Output: Ram Shita Ram Program 2: PHP <?php // input array $arr = array('a', '2', 'z', '8'); // current function print the // 1st element of the array. echo current($arr) ."\n"; // next function print the next // element of the current one. echo next($arr)."\n"; // again next function print the // next element of the current one. echo next($arr)."\n"; // prev function will print the previous element // of the current one. As right now current // element is 'z' so the previous element will be '2' echo prev($arr); ?> Output: a 2 z 2 Reference: https://www.php.net/manual/en/function.prev.php Create Quiz Comment K Kanchan_Ray Follow 0 Improve K Kanchan_Ray Follow 0 Improve Article Tags : Misc Web Technologies PHP PHP-array PHP-function +1 More Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like