PHP Conference Japan 2024

MultipleIterator::attachIterator

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

MultipleIterator::attachIterator附加迭代器資訊

說明

公開 MultipleIterator::attachIterator(Iterator $iterator, 字串|整數|null $info = null): void

附加迭代器資訊。

警告

此函式目前沒有說明文件;僅提供其參數列表。

參數

iterator

要附加的新迭代器。

info

迭代器的關聯資訊,必須是 整數字串null

返回值

說明...

錯誤/例外

如果 iterator 參數無效,或者 info 已經是關聯資訊,則會拋出 IllegalValueException(非法值例外)。

另請參閱

新增註釋

使用者貢獻的註釋 1 則註釋

andresdzphp at php dot net
13 年前
<?php
$ait_id
= new ArrayIterator(array('c1001', 'c1002', 'c1003'));
$ait_name = new ArrayIterator(array('apple', 'orange', 'banana'));
$ait_units = new ArrayIterator(array(756, 996, 2345));

$mit = new MultipleIterator(MultipleIterator::MIT_KEYS_ASSOC);
$mit->attachIterator($ait_id, "ID");
$mit->attachIterator($ait_name, "NAME");
$mit->attachIterator($ait_units, "UNITS");

echo
$mit->countIterators() . "\n"; //3

if ($mit->containsIterator($ait_id)) { //true
echo "ait_id iterator attached \n";
}

foreach (
$mit as $fruit) {
echo
"<pre>";
print_r($fruit);
echo
"</pre>";
}
?>

結果

3
ait_id 迭代器已附加

陣列
(
[ID] => c1001
[NAME] => apple
[UNITS] => 756
)
陣列
(
[ID] => c1002
[NAME] => orange
[UNITS] => 996
)
陣列
(
[ID] => c1003
[NAME] => banana
[UNITS] => 2345
)
To Top