我想访问从服务器作为 SOAP-Resonse 获得的数组属性。我使用 php soapclient 并在使用时获得以下输出$response = $client->$action($clientID);$array = json_decode(json_encode($xml), True);不幸的是,我无法访问诸如“tid”、“answer”等属性。我该怎么做(我可以在导入结果的地方使用 php 或 c#)Array( [0] => Array ( ) [1] => Array ( [0] => stdClass Object ( [tid] => 4103 [tdid] => 191 [qid] => 4103-1 [question] => Wie würden Sie Ihren Gesundheitszustand im Allgemeinen beschreiben ? [answer] => Ausgezeichnet. [score] => 100 [date] => 1558593404 [Fields] => Array ( ) ) [1] => stdClass Object ( [tid] => 4103 [tdid] => 191 [qid] => 4103-2 [question] => Im Vergleich zum vergangenen Jahr, wie würden Sie Ihren derzeitigen Gesundheitszustand beschreiben ? [answer] => Derzeit etwas besser als vor einem Jahr. [score] => 75 [date] => 1558593404 [Fields] => Array ( ) )
2 回答

繁星点点滴滴
TA贡献1803条经验 获得超3个赞
您有一组对象数组,因此要访问它们,您需要使用$array[index/key][index/key]直到达到对象所在的级别,然后使用[]->它来访问它。
你大概要循环,所以在你的循环中,你需要做一些检查,比如is_array, isset, is_object, 或 acount来看看是否有任何事情要做,它看起来像这样:
foreach($result as $arr) {
if(count($arr) < 1) continue;//there are no entries in this array
foreach($arr as $obj) {
if(isset($obj->tid)) {
//do your stuff
}
}
}
array_column如果您只需要 tid,您可以通过提取我们使用的所有数据来简化这一点,这取决于您的目标是什么 - 但这应该使您朝着正确的方向前进。您也可以array_map根据需要查看
- 2 回答
- 0 关注
- 110 浏览
添加回答
举报
0/150
提交
取消