To get the data that you want to receive, you need to navigate through several nested objects. Objects are of type stdClass. I understand that you can access nested objects in stdClass, but I'm going to assign them to arrays to make indexing easier.
So start with:
<?php $client = new SoapClient('the API wsdl'); $param = array('LicenseKey' => 'a guid'); $result = $client->GetUnreadIncomingMessages($param);
You now have $ result vavialble of type stdClass. This object also has one stdClass object called GetUnreadIncomingMessagesResult. This object, in turn, contains an array called "SMSIncomingMessage". This array contains a variable number of stdClass objects that contain the desired data.
So we do the following:
$outterArray = ((array)$result); $innerArray = ((array)$outterArray['GetUnreadIncomingMessagesResult']); $dataArray = ((array)$innerArray['SMSIncomingMessage']);
Now we have an array containing each object from which we want to extract data. Therefore, we iterate over this array to obtain a holder object, drop the storage object into an array, and extract the necessary information. You do it like this:
foreach($dataArray as $holdingObject) { $holdingArray = ((array)$holdingObject); $phoneNum = $holdingArray['FromPhoneNumber']; $message = $holdingArray['Message']; echo"<div>$fphone</div> <div>$message</div>"; } ?>
This will give you the result you are looking for. You can customize where you index holdArray to get any specific information you are looking for.
The full code is as follows:
<?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>"; } ?>
source share