我有以下名为“$ order”的数组(由“print_r”打印出来):
stdClass Object
(
[products] => Array
(
[0] => stdClass Object
(
[data] => Array
(
[attributes] => Array
(
[ID] => Array
(
[0] => 57
)
)
)
)
)
)
我的问题是,如何引用“57”?我认为会是这样的:
$order->products[0]->data[attributes][ID][0];
但这不起作用。我错过了什么?
答案 0 :(得分:2)
$order->products[0]->data['attributes']['ID'][0]
答案 1 :(得分:2)
您缺少数组键的引号。否则,它会让PHP认为attributes
或ID
是常量(define('ID', 'foobar'); echo ID;
)。
$order->products[0]->data['attributes']['ID'][0];
答案 2 :(得分:0)
没关系。就像这样: $命令 - >产品[0] - >数据[ “属性”] [ “ID”] [0];