ArrayIterator::seek()函數是PHP中的內置函數,用於查找數組迭代器的位置。
用法:
void ArrayIterator::seek( int $position )
參數:該函數接受單個參數$position,該參數保存要尋找的位置。
返回值:該函數不返回任何值。
以下示例程序旨在說明PHP中的ArrayIterator::seek()函數:
程序1:
<?php
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
array(
"a" => 4,
"b" => 2,
"g" => 8,
"d" => 6,
"e" => 1,
"f" => 9
)
);
// Seek the position
$arrItr->seek(5);
// Display the element
echo $arrItr->current();
?>
輸出:
9
程序2:
<?php
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
array(
"b" => "for",
"a" => "Geeks",
"e" => "Science",
"c" => "Geeks",
"f" => "Portal",
"d" => "Computer"
)
);
// Check the validity of ArrayIterator
if($arrItr->valid()) {
// Seek the position
$arrItr->seek(3);
// Display the element
echo $arrItr->current();
}
?>
輸出:
Geeks
參考: https://www.php.net/manual/en/arrayiterator.seek.php
相關用法
- PHP ArrayIterator seek()用法及代碼示例
- PHP SplFileObject seek()用法及代碼示例
- PHP DirectoryIterator seek()用法及代碼示例
- PHP ArrayIterator key()用法及代碼示例
- PHP ArrayIterator next()用法及代碼示例
- PHP ArrayIterator uasort()用法及代碼示例
- PHP ArrayIterator current()用法及代碼示例
- PHP ArrayIterator uksort()用法及代碼示例
- PHP ArrayIterator unserialize()用法及代碼示例
- PHP ArrayIterator count()用法及代碼示例
- PHP ArrayIterator rewind()用法及代碼示例
- PHP ArrayIterator offsetSet()用法及代碼示例
- PHP ArrayIterator offsetGet()用法及代碼示例
- PHP ArrayIterator __construct()用法及代碼示例
- PHP ArrayIterator offsetUnset()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP | ArrayIterator seek() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。