PHP

PHP Menu

PHP

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

Definition

The reset() function moves the internal pointer to the first element of the array.

The reset() 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.
  • prev() – Moves the internal pointer of an array to the previous element, and returns its value.
  • end() – Moves the internal pointer of an array to its last element, and returns its value.
  • key() – Returns the key of the current element in an array.

Syntax

reset(array)

Parameters

Parameter Description
array Required. Specifies the array to use.

Example

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

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods