AppendIterator::next()函數是PHP中的內置函數,用於將元素移至下一個元素。
用法:
void AppendIterator::next( void )
參數:該函數不接受任何參數。
返回值:該函數不返回任何值。
以下示例程序旨在說明PHP中的AppendIterator::next()函數:
示例1:
<?php
// Declare an ArrayIterator
$arr1 = new ArrayIterator(array('G', 'e', 'e', 'k', 's'));
// Create a new AppendIterator
$itr = new AppendIterator;
// Append the ArrayIterator element
$itr->append($arr1);
// Display the current element of iterator
var_dump($itr->current());
// Use AppendIterator::next() function to
// move into next element
$itr->next();
// Display the current element of iterator
var_dump($itr->current());
?>
輸出:
string(1) "G" string(1) "e"
示例2:
<?php
// Declare an ArrayIterator
$arr1 = new ArrayIterator(
array(
"a" => "Geeks",
"b" => "for",
"c" => "Geeks"
)
);
$arr2 = new ArrayIterator(
array(
"x" => "Computer",
"y" => "Science",
"z" => "Portal"
)
);
// Create a new AppendIterator
$itr = new AppendIterator;
$itr->append($arr1);
$itr->append($arr2);
$itr->rewind();
while ($itr->valid()) {
echo "ArrayIterator Key: " . $itr->key() .
" ArrayIterator Value: " . $itr->current() . "\n";
$itr->next();
}
?>
輸出:
ArrayIterator Key: a ArrayIterator Value: Geeks ArrayIterator Key: b ArrayIterator Value: for ArrayIterator Key: c ArrayIterator Value: Geeks ArrayIterator Key: x ArrayIterator Value: Computer ArrayIterator Key: y ArrayIterator Value: Science ArrayIterator Key: z ArrayIterator Value: Portal
參考: https://www.php.net/manual/en/appenditerator.next.php
相關用法
- PHP AppendIterator key()用法及代碼示例
- PHP AppendIterator rewind()用法及代碼示例
- PHP AppendIterator valid()用法及代碼示例
- PHP AppendIterator append()用法及代碼示例
- PHP AppendIterator __construct()用法及代碼示例
- PHP AppendIterator current()用法及代碼示例
- PHP AppendIterator getIteratorIndex()用法及代碼示例
- d3.js d3.lab()用法及代碼示例
- PHP dir()用法及代碼示例
- p5.js int()用法及代碼示例
- d3.js d3.rgb()用法及代碼示例
- d3.js d3.hcl()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | AppendIterator next() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。