2013-04-05 48 views
1

我對象名字是$ distinct1

print_r($distinct1)顯示下面的對象,但是當我嘗試做

echo $distinct1->properties->city 

OR

echo $distinct1->distinct_id 

我沒有得到任何價值回報。任何想法發生了什麼?

stdClass Object 
(
    [$distinct_id] => AAA 
    [$properties] => stdClass Object 
     (
      [$city] => Palo Alto 
      [$country_code] => US 
      [$region] => California 
      [$name] => John Smith 
) 
) 
+0

Uhhh是你的字段名爲''properties''或''$ properties''? – miorel 2013-04-05 22:46:49

回答

2

嗯,如果你的屬性是真名叫這樣的:

$distinct1->{'$properties'}->{'$city'} 

但如果可能的話,我會考慮這樣做這樣說,這&解決它存在的機制。

1

該對象的屬性名實際上以$開頭,適用於任何奇怪的原因。

echo $distinct1->{'$properties'}->{'$city'}; 
+0

謝謝。這工作。我從第三方API提取數據,不知道爲什麼他們在屬性名稱前使用了$。 – user2250908 2013-04-05 22:52:09