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>"; ?>
Code running result:
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); ?>
#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. ExampleUse 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); ?>
php array function current() definition and usageDetailed 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!