reset

(PHP 4, PHP 5, PHP 7, PHP 8)

resetSet the internal pointer of an array to its first element

Description

reset(array|object &$array): mixed

reset() rewinds array's internal pointer to the first element and returns the value of the first array element.

Parameters

array

The input array.

Return Values

Returns the value of the first array element, or false if the array is empty.

Warning

This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

Changelog

Version Description
8.1.0 Calling this function on objects is deprecated. Either use get_mangled_object_vars() on the object first, or use ArrayIterator.

Examples

Example #1 reset() example

<?php

$array 
= array('step one''step two''step three''step four');

// by default, the pointer is on the first element
echo current($array) . "<br />\n"// "step one"

// skip two steps
next($array);
next($array);
echo 
current($array) . "<br />\n"// "step three"

// reset pointer, start again on step one
reset($array);
echo 
current($array) . "<br />\n"// "step one"

?>

Notes

Note: The return value for an empty array is indistinguishable from the return value in case of an array which has a bool false first element. To properly check the value of the first element of an array which may contain false elements, first check the count() of the array, or check that key() is not null, after calling reset().

See Also

  • current() - Return the current element in an array
  • each() - Return the current key and value pair from an array and advance the array cursor
  • end() - Set the internal pointer of an array to its last element
  • next() - Advance the internal pointer of an array
  • prev() - Rewind the internal array pointer
  • array_key_first() - Gets the first key of an array

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Definition of stored procedures - an introduction

Stored procedures are predefined SQL code blocks that are stored in a database and can be called up as required. ...

Bernie

Autor : ebiz-consult GmbH & Co. KG
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial