CachingIterator::__construct()函數是PHP中的內置函數,用於為迭代器構造新的CachingIterator對象。
用法:
public CachingIterator::__construct( Iterator $iterator, int $flags = self::CALL_TOSTRING )
參數:該函數接受上述和以下描述的兩個參數:
- $iterator:此參數保存高速緩存的迭代器。
- $flags:此參數保存標誌的位掩碼。
返回值:該函數不返回任何值。
以下示例程序旨在說明PHP中的CachingIterator::__construct()函數:
示例1:
<?php
// Declare an array
$arr = array('G', 'e', 'e', 'k', 's');
// Create a new CachingIterator
$cachIt = new CachingIterator(
new ArrayIterator($arr),
CachingIterator::FULL_CACHE
);
// Display the result
foreach($cachIt as $element) {
echo $element . " ";
}
?>
輸出:
G e e k s
示例2:
<?php
// Declare an ArrayIterator
$arr = array(
"a" => "Geeks",
"b" => "for",
"c" => "Geeks",
"d" => "Computer",
"e" => "Science",
"f" => "Portal"
);
// Create a new CachingIterator
$cachIt = new CachingIterator(
new ArrayIterator($arr),
CachingIterator::FULL_CACHE
);
// Display the result
foreach($cachIt as $key => $value) {
echo $key . " => " . $value . "\n";
}
?>
輸出:
a => Geeks b => for c => Geeks d => Computer e => Science f => Portal
參考: https://www.php.net/manual/en/cachingiterator.construct.php
相關用法
- PHP CachingIterator next()用法及代碼示例
- PHP CachingIterator key()用法及代碼示例
- PHP CachingIterator getCache()用法及代碼示例
- PHP CachingIterator getInnerIterator()用法及代碼示例
- PHP CachingIterator getFlags()用法及代碼示例
- PHP CachingIterator current()用法及代碼示例
- PHP CachingIterator setFlags()用法及代碼示例
- PHP CachingIterator rewind()用法及代碼示例
- d3.js d3.set.has()用法及代碼示例
- d3.js d3.map.get()用法及代碼示例
- d3.js d3.set.add()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | CachingIterator __construct() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。