How to use php reset function

青灯夜游
Release: 2023-02-22 21:08:01
Original
4396 people have browsed it

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)
Copy after login

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); //指向数组中第一个元素 西门
?>
Copy after login

Output:

无忌
西门
Copy after login

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); 
  
?>
Copy after login

Output:

Delhi
Kolkata
Delhi
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template