php 迭代器使用

 /**
* 执行入口
* @author tianyunchong
* Time: 4:48 pm
* @return null
*/
public function run()
{
/** 遍历下所有的意向用户 */
foreach ($this->xrangePurpose() as $value) {
$purposeArr = json_decode($value, true);
$this->buildInqBuy($purposeArr);
}
} /**
* 意向用户处理迭代器
* @author tianyunchong
* Time: 4:49 pm
* @return string
*/
private function xrangePurpose()
{
$id = 0;
while (1) {
$purposeModel = InqPurposeuser::findFirst(array(
"conditions" => "id > ?1",
"bind" => array(1 => $id),
"order" => "id asc",
"limit" => 1,
));
if (empty($purposeModel)) {
break;
}
$id = $purposeModel->id;
yield json_encode($purposeModel->toArray());
}
}
上一篇:【LOJ #6094. 「Codeforces Round #418」归乡迷途】


下一篇:马克飞象 Markdown 使用和学习