打印特定的SOAP响应

时间:2019-04-11 05:21:21

标签: php soap

我使用以下方法从客户端获得肥皂响应:

Array (
 [return] => Array (
 [responseCode] => 200 [responseMessage] => SUCCESS [subscriberProfile] => Array (
 [entry] => Array ( 
 [0] => Array ( [key] => SUBSCRIBER_IDENTITY [value] => 1234567890 ) ) ) ) ) 

和打印它的php代码:

Response Code: <?php echo $profile->return->responseCode; ?> - <?php echo $profile->return->responseMessage; ?><br />
Identity: <?php echo $profile->return->subscriberProfile->entry->SUBSCRIBER_IDENTITY; ?></br />

打印在浏览器上的响应代码,但不用于标识。知道为什么吗?我认为路径未正确调用

还尝试了类似的操作:<?php echo $profile->return->responseCode->subscriberProfile->entry[0]->SUBSCRIBER_IDENTITY; ?></br />

谢谢

1 个答案:

答案 0 :(得分:4)

因为您的entry值是包含key/value对的对象数组,所以您必须找到正确的键才能输出其值。尝试这样的事情:

foreach ($response->return->subscriberProfile->entry as $entry) {
    if ($entry->key == 'SUBSCRIBER_IDENTITY') echo $entry->value;
}

输出:

1234567890

Demo on 3v4l.org