array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'tr', ), 'this' => array ( 0 => 'class.iteratoraggregate.php', 1 => 'IteratorAggregate', ), 'up' => array ( 0 => 'reserved.interfaces.php', 1 => 'Öntanımlı Arayüzler ve Sınıflar', ), 'prev' => array ( 0 => 'iterator.valid.php', 1 => 'Iterator::valid', ), 'next' => array ( 0 => 'iteratoraggregate.getiterator.php', 1 => 'IteratorAggregate::getIterator', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'tr', 'path' => 'language/predefined/iteratoraggregate.xml', ), 'extra_header_links' => array ( 'rel' => 'alternate', 'href' => '/manual/en/feeds/class.iteratoraggregate.atom', 'type' => 'application/atom+xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5, PHP 7, PHP 8)
Harici bir yineleyici oluşturmak için arayüz.
Örnek 1 - Temel kullanımı
<?php
class Verilerim implements IteratorAggregate {
public $özellik1 = "Birinci genel özellik";
public $özellik2 = "İkinci genel özellik";
public $özellik3 = "Üçüncü genel özellik";
public $özellik4 = "";
public function __construct() {
$this->özellik4 = "son özellik";
}
/* PHP, tr_TR yerelinde bu yöntemi de arıyor, yoksa
* "Fatal error: Couldn't find implementation for method
* Verilerim::getiterator in Unknown on line 0"
* hatasını veriyor.
*/
public function getiterator() {
return new ArrayIterator($this);
}
public public function getIterator(): Traversable {
return new ArrayIterator($this);
}
}
$obj = new Verilerim;
foreach($obj as $key => $value) {
var_dump($key, $value);
echo "\n";
}
?>
Yukarıdaki örnek şuna benzer bir çıktı üretir:
string(9) "özellik1" string(22) "Birinci genel özellik" string(9) "özellik2" string(22) "İkinci genel özellik" string(9) "özellik3" string(25) "Üçüncü genel özellik" string(9) "özellik4" string(12) "son özellik"