脚本宝典收集整理的这篇文章主要介绍了从PHP中的SoapClient返回中检索特定值,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
<?PHP $client = new SOApClient('the API wsdl'); $param = array( 'LicenseKey' => 'a guid' ); $result = $client->GetUnreadIncomingMessages($param); echo "<PRe>"; print_r($result); echo "</pre>"; ?>
stdClass Object ( [GetUnreadIncomingMessagesResult] => stdClass Object ( [SMSIncomingMessage] => Array ( [0] => stdClass Object ( [FromPhoneNumber] => the number [IncomingMessageiD] => message ID [MatchedMessageID] => [Message] => Hello there [ResponseReceiveDate] => 2012-09-20T20:42:14.38 [ToPhoneNumber] => another number ) [1] => stdClass Object ( [FromPhoneNumber] => the number [IncomingMessageID] => [MatchedMessageID] => [Message] => hello again [ResponseReceiveDate] => 2012-09-20T20:42:20.69 [ToPhoneNumber] => another number ) ) ) )
所以从以下开始:
<?PHP $client = new SoapClient('the API wsdl'); $param = array('LicenseKey' => 'a guid'); $result = $client->GetUnreadIncomingMessages($param);
您现在有一个类型为stdClass的$result vavialble.这里有一个stdClass类型的对象叫做“GetUnreadIncomingMessagesResult”.该对象又包含一个名为“SMSIncomingMessage”的数组.该数组包含可变数量的stdClass对象,用于保存所需的数据.
所以我们做了以下事情:
$outterArray = ((array)$result); $innerArray = ((array)$outterArray['GetUnreadIncomingMessagesResult']); $dataArray = ((array)$innerArray['SMSIncomingMessage']);
现在我们有一个数组,包含我们想要从中提取数据的每个对象.因此,我们遍历此数组以获取保持对象,将保持对象强制转换为数组,然后提取必要的信息.你这样做如下:
foreach($dataArray as $holdingObject) { $holdingArray = ((array)$holdingObject); $phoneNum = $holdingArray['FromPhoneNumber']; $message = $holdingArray['Message']; echo"<div>$fphone</div> <div>$message</div>"; } ?>
这应该可以为您提供所需的输出.您可以调整您对holdingArray编制索引的位置,以获取您要查找的任何特定信息.
完整的代码如下:
<?PHP $client = new SoapClient('the API wsdl'); $param = array('LicenseKey' => 'a guid'); $result = $client->GetUnreadIncomingMessages($param); $outterArray = ((array)$result); $innerArray = ((array)$outterArray['GetUnreadIncomingMessagesResult']); $dataArray = ((array)$innerArray['SMSIncomingMessage']); foreach($dataArray as $holdingObject) { $holdingArray = ((array)$holdingObject); $phoneNum = $holdingArray['FromPhoneNumber']; $message = $holdingArray['Message']; echo"<div>$fphone</div> <div>$message</div>"; } ?>
以上是脚本宝典为你收集整理的从PHP中的SoapClient返回中检索特定值全部内容,希望文章能够帮你解决从PHP中的SoapClient返回中检索特定值所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。