next函数
PHP next()函数 (PHP next() function)
next() function firstly moves the current pointer to the next element and returns the element.
next()函数首先将当前指针移动到下一个元素,然后返回该元素。
Syntax:
句法:
next(array);
Note: As we have discussed in the last post (current() function in PHP) that an array has a pointer that points to the first element by default, next() function can be used to move the pointer to next element and then print it.
注意:正如我们在上一篇文章( PHP中的current()函数 )中所讨论的那样,数组默认具有指向第一个元素的指针, next()函数可用于将指针移至下一个元素,然后进行打印它。
Examples:
例子:
Input:
$arr1 = array(10, 20, 30, 40, 50);
Function call:
next($arr1);
Output:
20
Input:
$arr2 = array("name" => "Amit", "age" => 21, "Gender" => "Male");
Function call:
next($arr2);
Output:
21
PHP code:
PHP代码:
<?php
$arr1 = array(10, 20, 30, 40, 50);
$arr2 = array("name" => "Amit", "age" => 21, "Gender" => "Male");
echo current($arr1) . "\n"; //print first element
echo next($arr1) ."\n"; //move to next element and print
echo next($arr1) ."\n"; //move to next element and print
echo current($arr2) . "\n"; //print first element
echo next($arr2) ."\n"; //move to next element and print
echo next($arr2) ."\n"; //move to next element and print
?>
Output
输出量
10
20
30
Amit
21
Male
翻译自: https://www.includehelp.com/php/next-function-with-example.aspx
next函数