您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP设计模式 迭代器模式,php设计模式模式_PHP教程

2024/11/19 20:51:10发布24次查看
php设计模式 迭代器模式,php设计模式模式迭代器模式,在不需要了解内部实现的前提下,遍历一个聚合对象的内部元素。相比于传统的编程模式,迭代器模式可以隐藏遍历元素所需要的操作。
allhacl.php
query('select id from ha_cl'); $this->ids = $result->fetch_all(mysqli_assoc); }
/**
* 返回当前元素
*/ function current(){ $id = $this->ids[$this->index]['id']; return factory::gethacl($id); }
/**
* 向前移动到下一个元素
*/ function next(){ $this->index ++; } /** * 返回到迭代器的第一个元素 */ function rewind(){ $this->index = 0; } /** * 查询当前位置是否有数据 */ function valid(){ return $this->index - count($this->ids); }
/**
* 返回当前元素的键
*/ function key(){ return $this->index; }}
index.php
$hacls = new \baobab\allhacl();foreach($hacls as $hacl){ var_dump($hacl->haclname);}
hacl类相关内容参考数据对象映射模式。http://www.cnblogs.com/tianxintian22/p/5232016.html
http://www.bkjia.com/phpjc/1110970.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1110970.htmltecharticlephp设计模式 迭代器模式,php设计模式模式 迭代器模式,在不需要了解内部实现的前提下,遍历一个聚合对象的内部元素。相比于传统的编...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product