ArrayIterator::offsetGet()函數是PHP中的內置函數,用於獲取偏移量的值。
用法:
mixed ArrayIterator::offsetGet( mixed $index )
參數:該函數接受單個參數$index,該參數保存要從中獲取值的偏移量。
返回值:該函數返回偏移量索引處的值。
以下示例程序旨在說明PHP中的ArrayIterator::offsetGet()函數:
程序1:
<?php
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
array(
"a" => 4,
"b" => 2,
"g" => 8,
"d" => 6,
"e" => 1,
"f" => 9
)
);
// Value present at index "a"
echo ($arrItr->offsetGet("a")) . " ";
// Value present at index "g"
echo ($arrItr->offsetGet("g")) . " ";
// Value present at index "f"
echo ($arrItr->offsetGet("f"));
?>
輸出:
4 8 9
程序2:
<?php
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
array(
"for", "Geeks", "Science",
"Geeks", "Portal", "Computer"
)
);
// Print the value at index 1
echo $arrItr->offsetGet(1) . "\n";
// Print the value at index 0
echo $arrItr->offsetGet(0) . "\n";
// Print the value at index 3
echo $arrItr->offsetGet(3);
?>
輸出:
Geeks for Geeks
參考: https://www.php.net/manual/en/arrayiterator.offsetget.php
相關用法
- PHP SplDoublyLinkedList offsetGet()用法及代碼示例
- PHP SplFixedArray offsetGet()用法及代碼示例
- PHP SplObjectStorage offsetGet()用法及代碼示例
- PHP ArrayObject offsetGet()用法及代碼示例
- PHP ArrayIterator next()用法及代碼示例
- PHP ArrayIterator key()用法及代碼示例
- PHP ArrayIterator unserialize()用法及代碼示例
- PHP ArrayIterator asort()用法及代碼示例
- PHP ArrayIterator __construct()用法及代碼示例
- PHP ArrayIterator uksort()用法及代碼示例
- PHP ArrayIterator offsetExists()用法及代碼示例
- PHP ArrayIterator seek()用法及代碼示例
- PHP ArrayIterator seek()用法及代碼示例
- PHP ArrayIterator offsetSet()用法及代碼示例
- PHP ArrayIterator current()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | ArrayIterator offsetGet() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。