Home  >  Article  >  Backend Development  >  How to use php reset function

How to use php reset function

青灯夜游
青灯夜游Original
2019-05-28 14:12:464327browse

The reset() function is a built-in function in PHP. The syntax is reset(array). It is used to move the internal pointer of any array to point to the first element of the array and output it. Simply put, it resets the internal pointer to point to the first element of the array.

How to use php reset function

How to use the php reset() function?

php The reset function points the internal pointer to the first element in the array and outputs it.

Syntax:

reset(array)

Parameters:

array: required. Specifies the array to use.

Return value: If successful, return the value of the first element in the array, if the array is empty, return FALSE.

Let’s take a look at how to use the php reset() function through an example.

Example 1:

<?php
header("content-type:text/html;charset=utf-8"); 
$people = array("西门", "灭绝", "无忌");
echo end($people); //指向最后一个元素 无忌
echo "<br>";
echo reset($people); //指向数组中第一个元素 西门
?>

Output:

无忌
西门

Example 2:

<?php 
  
$arr = array(&#39;Delhi&#39;, &#39;Kolkata&#39;, &#39;London&#39;); 
// 获取当前元素
print current($arr)."\n"; 
  
// 将内部指针移到下一个元素
next($arr); 
print current($arr)."\n"; 
  
//将内部指针移动到第一个元素
reset($arr); 
print current($arr); 
  
?>

Output:

Delhi
Kolkata
Delhi

The above is the detailed content of How to use php reset function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn