PHP 教程

PHP prev() 函数

时间:2023年05月07日 阅读:426
以下内容仅是站长或网友个人学习笔记、总结和研究收藏。不保证正确性,因使用而带来的风险与本站无关!
淘客轩-衣食住行外卖生活好助手

实例

输出数组中的当前元素、下一个元素和上一个元素的值:

<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");

echo current($people) . "<br>";
echo next($people) . "<br>";
echo prev($people);
?>

定义和用法

prev() 函数将内部指针指向数组中的上一个元素,并输出。

相关的方法:

  • next() - 将内部指针指向数组中的下一个元素,并输出。
  • current() - 返回数组中的当前元素的值。
  • end() - 将内部指针指向数组中的最后一个元素,并输出。
  • reset() - 将内部指针指向数组中的第一个元素,并输出。
  • each() - 返回当前元素的键名和键值,并将内部指针向前移动。

语法

  prev(array)  

参数 描述
array 必需。规定要使用的数组。

技术细节

返回值: 如果成功则返回数组中上一个元素的值,如果没有更多的数组元素则返回 FALSE。
PHP 版本: 4+

更多实例

实例 1

所有相关方法的演示:

<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");

echo current($people) . "<br>"; // The current element is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
echo current($people) . "<br>"; // Now the current element is Joe
echo prev($people) . "<br>"; // The previous element of Joe is Peter
echo end($people) . "<br>"; // The last element is Cleveland
echo prev($people) . "<br>"; // The previous element of Cleveland is Glenn
echo current($people) . "<br>"; // Now the current element is Glenn
echo reset($people) . "<br>"; // Moves the internal pointer to the first element of the array, which is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe

print_r (each($people)); // Returns the key and value of the current element (now Joe), and moves the internal pointer forward
?>

打赏
标签: PHP

本文地址:https://www.momojc.cn/php/php-prev-hwzg.html

上一篇:PHP pos() 函数
下一篇:PHP range() 函数

关于本站 | 隐私政策 | 免责声明 | 广告合作 | 我要投稿 | 后台管理

CopyRight © 2023-2024 MOMO教程 WWW.MOMOJC.CN , All Rights Reserved.

站长E-mail:378074730@qq.com 网站已运行:  运行时长:0.056 秒

京ICP备20029690号-1京ICP备20029690号-2 京公网安备11011402013892号京公网安备11011402013892号 中国互联网违法和不良信息举报中心 网络违法犯罪举报网站

本网站托管于 腾讯云 .由网站卫士提供网站加速和攻击防御服务 提供CDN加速/防御服务.由zblogcn强力驱动 又拍云提供CDN加速/云存储服务 51la网站统计