2014-03-27 47 views
0

我在看的数组是这样的:如何从此子数组中提取PHP字符串?

Array 
(
[0] => Array 
    (
     [0] => Bigcommerce\Api\Resources\ProductCustomField Object 
      (
       [ignoreOnCreate:protected] => Array 
        (
         [0] => id 
         [1] => product_id 
        ) 

       [ignoreOnUpdate:protected] => Array 
        (
         [0] => id 
         [1] => product_id 
        ) 

       [fields:protected] => stdClass Object 
        (
         [id] => 17 
         [product_id] => 3232 
         [name] => Artist 
         [text] => Test 
        ) 

       [id:protected] => 17 
       [ignoreIfZero:protected] => Array 
        (
        ) 

      ) 

    ) 

) 

我要检查,看看是否“艺术家”在一个PHP条件语句存在。但我不知道如何把'艺术家'变成一个字符串。

更新: 我没有找到懂得如何提取值转换成字符串,但我得到了我一直在寻找使用相关的Bigcommerce API的方法:

$customs = Bigcommerce::getProductCustomFields($product->id); 
foreach($customs as $custom) { 
if($custom->name == 'Artist'): // do something 
endif; 
} 
+0

有没有一种方法可以通过getter(例如'$ obj-> getFields()')来访问'ProductCustomField'保护的$ fields'属性? – Phil

+0

我不确定。我无法找到明确的文档,但我认为这应该查找自定义字段... Bigcommerce :: getProductCustomFields($ product-> id); 但我仍然不知道如何从中访问它。 – osakagreg

+0

您是否可以添加var_export($ yourArray),以便我们更容易地使用它并运行测试? – MJoraid

回答

2

好吧,看着source,看来你应该可以使用魔术__get的方法。尝试

$array[0][0]->name == 'Artist' 
+0

我没看过那个。这些功能可能更容易完成。但是我仍然对$字段对于我为产品创建的自定义值(这是艺术家的名字)感到困惑。 – osakagreg

相关问题