MultipleIterator::attachIterator

(PHP 5 >= 5.3.0, PHP 7)

MultipleIterator::attachIteratorAttaches iterator information

설명

public void MultipleIterator::attachIterator ( Iterator $iterator [, string $infos ] )

Attaches iterator information.

Warning

이 함수는 현재 문서화 되어있지 않습니다; 인수 목록만을 제공합니다.

인수

iterator

The new iterator to attach.

infos

The associative information for the Iterator, which must be an integer, a string, or NULL.

반환값

Description...

오류/예외

An IllegalValueException if the iterator parameter is invalid, or if infos is already associated information.

참고

add a note add a note

User Contributed Notes 2 notes

up
6
andresdzphp at php dot net
13 years ago
<?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>";
}
?>

Result:

3
ait_id iterator attached

Array
(
    [ID] => c1001
    [NAME] => apple
    [UNITS] => 756
)
Array
(
    [ID] => c1002
    [NAME] => orange
    [UNITS] => 996
)
Array
(
    [ID] => c1003
    [NAME] => banana
    [UNITS] => 2345
)
up
0
DDT
11 years ago
If you have multiple file upload fields named "files[]"...

<?php
if (isset($_FILES["files"])) {
  
$uploads = new MultipleIterator(MultipleIterator::MIT_KEYS_ASSOC);
  
$uploads->attachIterator(new ArrayIterator((array) $_FILES["files"]["name"]), "name");
  
$uploads->attachIterator(new ArrayIterator((array) $_FILES["files"]["size"]), "size");
  
$uploads->attachIterator(new ArrayIterator((array) $_FILES["files"]["type"]), "type");
  
$uploads->attachIterator(new ArrayIterator((array) $_FILES["files"]["tmp_name"]), "tmp_name");
  
$uploads->attachIterator(new ArrayIterator((array) $_FILES["files"]["error"]), "error");

   foreach (
$uploads as $file) {
      echo
htmlspecialchars($file["name"]) . " = {$file["size"]} bytes<br/>";
   }
}
?>
To Top