<?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"; if ($mit->containsIterator($ait_id)) { echo "ait_id 迭代器已附加 \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
)