搜索多维关联数组php

问题描述 投票:0回答:1

使用api我得到了一个数据数组。我要从中提取几个值。我该怎么做?

array(1) {
  ["return"]=>
  array(2) {
    ["ProductsItemCount"]=>
    string(2) "13"
    ["ProductsItem"]=>
    array(13) {
      [0]=>
      array(10) {
        ["Article"]=>
        string(7) "115 906"
        ["Name"]=>
        string(72) "Sprinter 208-316 95-06/LT 28-35 96-06"
        ["Brand"]=>
        string(5) "SACHS"
        ["Sklad1"]=>
        string(1) "0"
        ["Price"]=>
        int(0)
        ["Currency"]=>
        string(3) "EUR"
        ["Stock"]=>
        array(1) {
          ["StockItem"]=>
          array(4) {
            [0]=>
            array(6) {
              ["WarehCode"]=>
              string(9) "000000001"
              ["Price"]=>
              float(42.98)
             }
            [1]=>
            array(6) {
            ["Price"]=>
              float(42.98)
              ["Count"]=>
              string(3) "522"

必须接收:

$artikle = 115 906;
$Price = 42.98;
$Name = Sprinter 208-316 95-06/LT 28-35 96-06;
$Brand = SACHS;
$Currency= EUR

如何获得?我试图申请该课程,但一无所获

class ProductFilterIterator extends \FilterIterator
{
     protected $filter;

    .................................................
........................................

         return $current['Article'] == $this->filter;

     }
}

$iterator = (new \ArrayObject($data))->getIterator();
$filter1 = new ProductFilterIterator($iterator, '115 906');

foreach ($filter1 as $data) {
}

请帮助我解决这个问题。我做错了什么?您可能需要搜索前叉?

php arrays class foreach php-7
1个回答
0
投票
class ProductFilterIterator extends \FilterIterator
{
   protected $filter;

   public function __construct(\Iterator $iterator, string $filter)
   {
       $this->filter = $filter;
       parent::__construct($iterator);
   }

   public function accept() : bool
   {
       $current = $this->getInnerIterator()->current();
       return $current['Article'] == $this->filter;
   }
}

$iterator = (new \ArrayObject($obj))->getIterator();
$filter = new ProductFilterIterator($iterator, '115 906');

foreach ($filter as $data) {
  echo "<pre>";
 // var_dump($obj);

致命错误:未捕获InvalidArgumentException:传递的变量不是62中的数组或对象62 ..... $ iterator =(new \ ArrayObject($ obj))-> getIterator();

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.