PHP

PHP Menu

PHP

prev() Function - Definition, Syntax, Parameters, Examples

Definition

The prev() function moves the internal pointer to, and outputs, the previous element in the array.

The prev() function is commonly used along with the following functions:

  • current() – Returns the value of the current element in an array.
  • next() – Moves the internal pointer of an array to the next element, and returns its value.
  • end() – Moves the internal pointer of an array to its last element, and returns its value.
  • reset() – Set the internal pointer of an array to its first element, and returns its value.
  • key() – Returns the key of the current element in an array.

Syntax

prev(array)

Parameters

Parameter Description
array Required. Specifies the array to use.

Example

<?php
// Indexed Array $cities = array("New York", "London", "Tokyo", "Berlin", "Cairo"); echo current($cities) . "<br>"; echo next($cities) . "<br>"; echo prev($cities) . "<br>";
// Examples in conjunction with other related functions echo current($cities) . "<br>"; echo end($cities) . "<br>"; echo current($cities) . "<br>"; echo prev($cities) . "<br>"; echo current($cities) . "<br>"; echo next($cities) . "<br>"; echo current($cities) . "<br>"; echo reset($cities) . "<br>"; echo current($cities) . "<br>"; echo key($cities) . "<br>";

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods