Home > Backend Development > PHP Tutorial > Detailed explanation of usage examples of PHP array operation functions current, next and reset functions

Detailed explanation of usage examples of PHP array operation functions current, next and reset functions

怪我咯
Release: 2023-03-08 06:14:02
Original
2190 people have browsed it

What are the uses of php current, next and reset functions?

The current() function in php returns the current element (unit, which is the first element of the array) in the array. The next() function points the internal pointer to the next element in the array, and Output the value of the element. The reset() function points the internal pointer to the first element in the array and outputs the value of the element. This article mainly introduces the usage of current, next and reset functions in PHP, with examples. This article describes the specific usage of the functions current, next and reset for array operations in PHP. It has certain reference value for in-depth understanding of the usage of arrays. I hope it will be helpful to everyone's understanding of arrays

current function

current() function returns the value of the current element in the array. Each array has an internal pointer pointing to its "current" element, initially pointing to it. Inserts the first element into the array. This function does not move the array internal pointer

Example##

<?php
$people = array("Bill", "Steve", "Mark", "David");
echo current($people) . "<br>";
?>
Copy after login

Code running result:

Detailed explanation of usage examples of PHP array operation functions current, next and reset functions

next function

next() function points the internal pointer to the next in the array element, and output the value of the element.

Example

Use php current and next functions to output the value of the current element and the next element in the array: The code is as follows

<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>";
echo next($people);
?>
Copy after login

Code running result:

Detailed explanation of usage examples of PHP array operation functions current, next and reset functions

#reset function

set() function is to point the internal pointer to the array The first element in the array, and output the value of the element.

Example

Use the php current and next functions to output the value of the current element and the next element in the array, and then put the array The internal pointer is reset to the first element in the array. The code is as follows

<?php
$people = array("Bill", "Steve", "Mark", "David");
echo current($people) . "<br>";
echo next($people) . "<br>";
echo reset($people);
?>
Copy after login

Code running result:

Detailed explanation of usage examples of PHP array operation functions current, next and reset functions

##[Related article recommendations]

php array function current() definition and usage

Detailed explanation of php end() function and current() function

The above is the detailed content of Detailed explanation of usage examples of PHP array operation functions current, next and reset functions. 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