array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.next.php', 1 => 'next', ), 'up' => array ( 0 => 'ref.array.php', 1 => '数组 函数', ), 'prev' => array ( 0 => 'function.natsort.php', 1 => 'natsort', ), 'next' => array ( 0 => 'function.pos.php', 1 => 'pos', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/array/functions/next.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
next — 将数组中的内部指针向前移动一位
next() 和 current() 的行为类似,只有一点区别,在返回值之前将内部指针向前移动一位。这意味着它返回的是下一个数组单元的值并将数组指针向前移动了一位。
返回数组内部指针指向的下一个单元的值,或当没有更多单元时返回 false
。
版本 | 说明 |
---|---|
8.1.0 | 弃用在 object 上调用此函数。 要么首先使用 get_mangled_object_vars() 将 object 转换为 array,要么使用实现 Iterator 的类提供的方法,例如 ArrayIterator。 |
7.4.0 | SPL 类的实例现在被视为没有属性的空对象,而不是调用与此函数同名的 Iterator 方法。 |
示例 #1 next() 及相关函数的用法示例
<?php
$transport = array('foot', 'bike', 'car', 'plane');
$mode = current($transport); // $mode = 'foot';
$mode = next($transport); // $mode = 'bike';
$mode = next($transport); // $mode = 'car';
$mode = prev($transport); // $mode = 'bike';
$mode = end($transport); // $mode = 'plane';
?>