AppendIterator::getIteratorIndex()函数是PHP中的内置函数,用于获取当前内部迭代器的索引。
用法:
int AppendIterator::getIteratorIndex( void )
参数:该函数不接受任何参数。
返回值:此函数返回一个整数值,该值是当前内部迭代器的从零开始的索引。
以下示例程序旨在说明PHP中的AppendIterator::getIteratorIndex()函数:
示例1:
<?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 elements
foreach ($itr as $key => $val) {
echo "Iterator Index: " . $itr->getIteratorIndex()
. " Key : " . $key . " Value: " . $val . "\n";
}
?>
输出:
Iterator Index: 0 Key : 0 Value: Geeks Iterator Index: 0 Key : 1 Value: for Iterator Index: 0 Key : 2 Value: Geeks Iterator Index: 1 Key : 0 Value: Computer Iterator Index: 1 Key : 1 Value: Science Iterator Index: 1 Key : 2 Value: Portal
示例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);
// Display the elements
foreach ($itr as $key => $val) {
echo "Iterator Index: " . $itr->getIteratorIndex()
. " Key : " . $key . " Value: " . $val . "\n";
}
?>
输出:
Iterator Index: 0 Key : a Value: Geeks Iterator Index: 0 Key : b Value: for Iterator Index: 0 Key : c Value: Geeks Iterator Index: 1 Key : x Value: Computer Iterator Index: 1 Key : y Value: Science Iterator Index: 1 Key : z Value: Portal
参考: https://www.php.net/manual/en/appenditerator.getiteratorindex.php
相关用法
- PHP Imagick getIteratorIndex()用法及代码示例
- PHP AppendIterator next()用法及代码示例
- PHP AppendIterator key()用法及代码示例
- PHP AppendIterator __construct()用法及代码示例
- PHP AppendIterator append()用法及代码示例
- PHP AppendIterator valid()用法及代码示例
- PHP AppendIterator rewind()用法及代码示例
- PHP AppendIterator current()用法及代码示例
- p5.js sin()用法及代码示例
- p5.js tan()用法及代码示例
- p5.js red()用法及代码示例
- p5.js log()用法及代码示例
注:本文由纯净天空筛选整理自jit_t大神的英文原创作品 PHP | AppendIterator getIteratorIndex() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。