查詢

CachingIterator::hasNext()函式—用法及示例

「 檢查當前迭代器是否有下一個元素可用 」


函式名稱:CachingIterator::hasNext() 適用版本:PHP 5 >= 5.1.0, PHP 7

函式描述: CachingIterator::hasNext() 方法用於檢查當前迭代器是否有下一個元素可用。

用法: bool CachingIterator::hasNext ( void )

引數: 此函式沒有任何引數。

返回值: 如果當前迭代器有下一個元素可用,則返回 true,否則返回 false。

示例: 以下示例演示瞭如何使用CachingIterator::hasNext()方法檢查迭代器的下一個元素:

$fruitArray = array("apple", "banana", "cherry");
$fruitIterator = new CachingIterator(new ArrayIterator($fruitArray));

if ($fruitIterator->hasNext()) {
    echo "Next element is available.";
} else {
    echo "Next element is not available.";
}

輸出結果: Next element is available.

補充糾錯
下一個函式: CachingIterator::key()函式
熱門PHP函式
分享連結