【发布时间】:2020-03-20 04:29:06
【问题描述】:
借助 ProductFilterIterator 类想要获取数据
class ProductFilterIterator extends \FilterIterator
{
protected $filter;
protected $length;
public function __construct(\Iterator $iterator, $filter)
{
$this->filter = $filter;
$this->length = -strlen($filter);
parent::__construct($iterator);
}
public function accept() : bool
{
$current = $this->getInnerIterator()->current();
return substr($current['Товар'], $this->length) == $this->filter;
}
}
$iterator = (new \ArrayObject($obj['items']))->getIterator();
$filter = new ProductFilterIterator($iterator, $arPart['ARTICLE']);
foreach ($filter as $obj) {
echo "<pre>";
我收到一个错误 - 致命错误:无法声明类 ProductFilterIterator,因为该名称已在使用中
【问题讨论】:
-
你能指定你正在使用的框架吗?
-
你看过之前的教程了吗? blog.floriancourgey.com/2018/05/…
-
因此,如果您在没有 Prestashop 的情况下工作,您需要将 Smarty 集成到您的系统中。
-
这很难解释...
标签: php function class php-7 filter-iterator