PHP next() 函数
实例
输出数组中的当前元素和下一个元素的值:
<?php $people = array("Bill", "Steve", "Mark", "David"); echo current($people) . "
"; echo next($people); ?>
定义和用法
next() 函数将内部指针指向数组中的下一个元素,并输出。
相关的方法:
语法
next(array)
参数 | 描述 |
---|---|
array | 必需。规定要使用的数组。 |
说明
next() 和 current() 的行为类似,只有一点区别,在返回值之前将内部指针向前移动一位。这意味着它返回的是下一个数组单元的值并将数组指针向前移动了一位。如果移动指针的结果超出了数组单元的末端,则 next() 返回 FALSE。
ຄວາມຕ້ອງເຫັນ:ຄວາມງານ: ຖ້າສາຍກວມມີຫຼັກສາຍສະຫຼາກຫຼືຄະແນນຄວາມຂອງຫຼັກສາຍແມ່ນ 0 ນັ້ນຫົວຫຼັກການວຽກຈະກັບຄືນ FALSE. ເພື່ອກວດສອບສາຍທີ່ອາດມີຫຼັກສາຍສະຫຼາກຫຼືຄະແນນຄວາມຂອງຫຼັກສາຍແມ່ນ 0 ກະລຸນາເບິ່ງຫົວຫຼັກການວຽກ each().
ຂໍ້ມູນດ້ານເຕັກນິກ
ຄະແນນຄວາມທີ່ກັບຄືນ | ຖ້າປະສົບຜົນສຳເລັດແລ້ວຈະກັບຄືນຄະແນນຄວາມຈາກອີກຢ່າງໜ້ານັບໃນສາຍອີກຢ່າງໜ້ານັບຫຼືບໍ່ມີອີກຢ່າງໜ້ານັບຫຼືບໍ່ມີອີກຈະກັບຄືນ FALSE。 |
PHP Version: | 4+ |
More Examples
Example 1
Demonstrate all related methods:
<?php $people = array("Bill", "Steve", "Mark", "David"); echo current($people) . "<br>"; // The current element is Bill echo next($people) . "<br>"; // Bill's next element is Steve echo current($people) . "<br>"; // The current element is Steve echo prev($people) . "<br>"; // The previous element of Steve is Bill echo end($people) . "<br>"; // The last element is David echo prev($people) . "<br>"; // The element before David is Mark echo current($people) . "<br>"; // The current element is Mark echo reset($people) . "<br>"; // Moves the internal pointer to the first element of the array, i.e., Bill echo next($people) . "<br>"; // Bill's next element is Steve print_r (each($people)); // Returns the key name and value of the current element (currently Steve) and moves the internal pointer forward ?>