PHP 设计模式之迭代器模式
来源:互联网 发布:内部网络故障诊断工具 编辑:程序博客网 时间:2024/06/07 17:45
<?php// 在不需要了解内部实现的前提条件下,可以遍历一个聚合对象的内部元素// 相比于传统的编程模式,迭代器模式可以隐藏遍历元素所需的操作class AllUser implements Iterator{ private $ids; private $index; public function __construct() { $this->ids = [1, 2, 3, 4, 5, 6, 7]; } public function current() { return $this->ids[$this->index]; } public function next() { $this->index++; } // 第一个调用 valid public function valid() { return $this->index < count($this->ids); } // 重置整个迭代器 public function rewind() { $this->index = 0; } // 表示在迭代器中的位置 public function key() { return $this->index; }}$users = new AllUser;foreach ($users as $user) { print_r($user); echo "\n";}
阅读全文
0 0
- PHP设计模式漫谈之迭代器模式
- PHP设计模式之迭代器模式(Iterator)
- php中的设计模式之--迭代器模式
- php设计模式之迭代器模式
- PHP设计模式漫谈之迭代器模式
- php设计模式之迭代器模式
- PHP 设计模式之迭代器模式
- php 设计模式之 代理模式,适配器模式,外观模式
- Php设计模式之【迭代器模式Iterator Pattern】
- PHP草根论之设计模式-迭代器模式
- PHP设计模式中之装饰模式
- PHP设计模式之Factory模式
- PHP设计模式之AbstractFactory模式
- PHP设计模式之Builder模式
- PHP设计模式之Prototype模式
- PHP设计模式之Singleton模式
- PHP设计模式之装饰模式
- php设计模式之单例模式
- PHP 设计模式之装饰器模式
- 长按listview删除时position和id的解析以及类型的转换
- jsp上传图片servlet代码
- linux下休眠/待机命令
- scrapy-redis分布式爬取彩票网站信息
- PHP 设计模式之迭代器模式
- laravel sum 多个字段
- HDU6078Wavel Sequence
- RF+Appium环境配置五:Appium 配置(Setup_Appium_Server)
- 8月4日云栖精选夜读:澳门拥抱阿里云:全面应用智能技术_为城市装上“大脑”
- StringUtils工具类用法
- PHP 设计模式之数据对象映射模式
- 开灯问题
- Qt5.6连接MySQL5.6