PHP基礎(chǔ)之預(yù)定義接口3——IteratorAggregate接口
創(chuàng)建外部迭代器的接口。
接口摘要IteratorAggregate extends Traversable { /* 方法 */ abstract public Traversable getIterator ( void )}
Example #1 基本用法
<?php class myData implements IteratorAggregate {public $property1 = 'Public property one';public $property2 = 'Public property two';public $property3 = 'Public property three';public function __construct() { $this->property4 = 'last property';}public function getIterator() { return new ArrayIterator($this);} } $obj = new myData; foreach($obj as $key => $value) {var_dump($key, $value);echo 'n'; }?>
以上例程的輸出類似于:
string(9) 'property1'string(19) 'Public property one'string(9) 'property2'string(19) 'Public property two'string(9) 'property3'string(21) 'Public property three'string(9) 'property4'string(13) 'last property'?方法列表IteratorAggregate::getIterator?— 獲取一個(gè)外部迭代器
相關(guān)文章:
1. 如何在jsp界面中插入圖片2. ASP實(shí)現(xiàn)加法驗(yàn)證碼3. python selenium 獲取接口數(shù)據(jù)的實(shí)現(xiàn)4. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)5. 詳解JSP 內(nèi)置對(duì)象request常見用法6. 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算7. Python matplotlib 繪制雙Y軸曲線圖的示例代碼8. jsp EL表達(dá)式詳解9. JSP servlet實(shí)現(xiàn)文件上傳下載和刪除10. springboot集成與使用Sentinel的方法
