我想从任意数组的响应中获取结果。 下面是数组输出:
SimpleXMLElement Object
(
[GetCharitiesByKeywordResponse] => SimpleXMLElement Object
(
[GetCharitiesByKeywordResult] => SimpleXMLElement Object
(
[CharityList] => Array
(
[0] => SimpleXMLElement Object
(
[RegisteredCharityNumber] => 1175358
[SubsidiaryNumber] => 0
[CharityName] => LYDIARD PARK HERITAGE TRUST
[MainCharityName] => LYDIARD PARK HERITAGE TRUST
[RegistrationStatus] => Registered
[PublicEmailAddress] => info@lydiardtrust.org.uk
[MainPhoneNumber] => 07763059645
)
[1] => SimpleXMLElement Object
(
[RegisteredCharityNumber] => 1188662
[SubsidiaryNumber] => 0
[CharityName] => PALACE THEATRE & OPERA HOUSE TRUST
[MainCharityName] => PALACE THEATRE & OPERA HOUSE TRUST
[RegistrationStatus] => Registered
[PublicEmailAddress] => SheenaWrigley@theambassadors.com
[MainPhoneNumber] => 01612456636
)
我正在尝试打印第一个元素的“慈善名称”,通过下面的代码,但我得到了空值:
print "<br>Result = ". $parser['GetCharitiesByKeywordResponse']['GetCharitiesByKeywordResult']['CharityList']['0']['CharityName'];
需要帮忙把它打印出来。
谢谢
它是一个对象,不是数组。
试试这个:
$parser->GetCharitiesByKeywordResponse->GetCharitiesByKeywordResult->CharityList[0]->CharityName;