stdClass object and foreach loops

后端 未结 5 614
日久生厌
日久生厌 2020-12-03 05:48

I am using the following code to get data from a website using Soap.

$client = new SoapClient(\'http://some.url.here\');
class SMSParam {
    public $CellNu         


        
5条回答
  •  眼角桃花
    2020-12-03 06:14

    My take on it is to just always make sure you have an array of messages, even if it's an array of 1. That way you don't duplicate any processing.

    $smsMessages = is_array( $result->GetIncomingMessagesResult->SMSIncomingMessage )
        ? $result->GetIncomingMessagesResult->SMSIncomingMessage
        : array( $result->GetIncomingMessagesResult->SMSIncomingMessage );
    
    foreach ( $smsMessages as $smsMessage )
    {
        echo $smsMessage->Reference;
    }
    

提交回复
热议问题