array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.prev.php', 1 => 'prev', ), 'up' => array ( 0 => 'ref.array.php', 1 => '数组 函数', ), 'prev' => array ( 0 => 'function.pos.php', 1 => 'pos', ), 'next' => array ( 0 => 'function.range.php', 1 => 'range', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/array/functions/prev.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
prev — 将数组的内部指针倒回一位
array
The input array.
返回数组内部指针指向的前一个单元的值,或当没有更多单元时返回 false
。
版本 | 说明 |
---|---|
8.1.0 | 弃用在 object 上调用此函数。 要么首先使用 get_mangled_object_vars() 将 object 转换为 array,要么使用实现 Iterator 的类提供的方法,例如 ArrayIterator。 |
7.4.0 | SPL 类的实例现在被视为没有属性的空对象,而不是调用与此函数同名的 Iterator 方法。 |
示例 #1 prev() 及相关函数用法示例
<?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';
?>