AppendIterator::__construct()函數是PHP中的一個內置函數,用於構造AppendIterator。
用法:
public AppendIterator::__construct( void )
參數:該函數不接受任何參數。
返回值:該函數不返回任何值。
以下示例程序旨在說明PHP中的AppendIterator::__construct()函數:
示例1:
<?php
// Declare an ArrayIterator
$arr1 = new ArrayIterator(array('G', 'e', 'e', 'k', 's'));
$arr2 = new ArrayIterator(array('f', 'o', 'r'));
$arr3 = new ArrayIterator(array('G', 'e', 'e', 'k', 's'));
// Create a new AppendIterator
$itr = new AppendIterator;
$itr->append($arr1);
$itr->append($arr2);
$itr->append($arr3);
// Display the result
foreach ($itr as $key => $val) {
echo $key . " => " . $val . PHP_EOL;
}
?>
輸出:
0 => G 1 => e 2 => e 3 => k 4 => s 0 => f 1 => o 2 => r 0 => G 1 => e 2 => e 3 => k 4 => s
示例2:
<?php
// Declare an ArrayIterator
$arr1 = new ArrayIterator(array("Geeks", "for", "Geeks"));
$arr2 = new ArrayIterator(array("Computer", "Science", "Portal"));
// Create a new AppendIterator
$itr = new AppendIterator;
$itr->append($arr1);
$itr->append($arr2);
// Display the result
foreach ($itr as $key => $val) {
echo $key . " => " . $val . PHP_EOL;
}
?>
輸出:
0 => Geeks 1 => for 2 => Geeks 0 => Computer 1 => Science 2 => Portal
參考: https://www.php.net/manual/en/appenditerator.construct.php
相關用法
- PHP AppendIterator next()用法及代碼示例
- PHP AppendIterator key()用法及代碼示例
- PHP AppendIterator getIteratorIndex()用法及代碼示例
- PHP AppendIterator append()用法及代碼示例
- PHP AppendIterator valid()用法及代碼示例
- PHP AppendIterator current()用法及代碼示例
- PHP AppendIterator rewind()用法及代碼示例
- d3.js d3.min()用法及代碼示例
- PHP pow( )用法及代碼示例
- d3.js d3.map.get()用法及代碼示例
- p5.js value()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | AppendIterator __construct() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。