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. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)2. asp批量添加修改刪除操作示例代碼3. HTML5 Canvas繪制圖形從入門到精通4. 讀大數(shù)據(jù)量的XML文件的讀取問(wèn)題5. PHP循環(huán)與分支知識(shí)點(diǎn)梳理6. css代碼優(yōu)化的12個(gè)技巧7. 低版本IE正常運(yùn)行HTML5+CSS3網(wǎng)站的3種解決方案8. ASP實(shí)現(xiàn)加法驗(yàn)證碼9. ASP.NET MVC使用異步Action的方法10. jsp+servlet實(shí)現(xiàn)猜數(shù)字游戲
