无法迭代对象

时间:2018-02-24 21:20:57

标签: php

我有这个包含数组索引列表的对象:

["features"]=>
object(stdClass)#10 (1) {
  ["feature"]=>
  array(5) {
    [0]=>
    object(stdClass)#5 (2) {
      ["name"]=>
      string(14) "customer_email"
      ["value"]=>
      string(22) "foo@gmail.com"
    }
    [1]=>
    object(stdClass)#6 (2) {
      ["name"]=>
      string(18) "license_expiration"
      ["value"]=>
      string(19) "2018-02-25 00:00:00"
    }
  }
}

}

我试图以这种方式进行迭代:

foreach($keyDetails->features as $feature)
       {
         echo $feature;
           //if($feature["subscription_reference"]
       }

但是foreach永远不会被解雇,为什么?

1 个答案:

答案 0 :(得分:0)

你的foreach中缺少2个等级。首先pkey,然后feature

foreach ($keyDetails->pkey->features->feature as $feature)
{
     var_dump($feature) ;
}