首页 > 解决方案 > 我如何阅读这个对象的内容

问题描述

我正在用 PHP 开发一个短信阅读应用程序。我将 SMS 门户连接到应用程序并接收 SMS。

请帮我阅读这个数组对象并分别获取内容。

array(3) 
{ 
    [0]=> object(stdClass)#14 (8) 
        { 
            ["message"]=> string(3) "G56" 
            ["messageId"]=> int(1) 
            ["recipients"]=> string(11) "94714369777" 
            ["retries"]=> int(1) 
            ["sender"]=> object(stdClass)#15 (1) 
                { 
                    ["alias"]=> string(11) "94710200542" 
                } 
            ["sequenceNum"]=> int(1) 
            ["status"]=> int(1) 
            ["time"]=> string(25) "2018-10-13T10:40:17+05:30" 
        } 
    [1]=> object(stdClass)#16 (8) 
        { 
            ["message"]=> string(4) "A67i" 
            ["messageId"]=> int(1) 
            ["recipients"]=> string(11) "94714369777" 
            ["retries"]=> int(1) 
            ["sender"]=> object(stdClass)#17 (1) 
                { 
                    ["alias"]=> string(11) "94710200542" 
                } 
            ["sequenceNum"]=> int(1) 
            ["status"]=> int(1) 
            ["time"]=> string(25) "2018-10-13T10:40:21+05:30" 
        } 
    [2]=> object(stdClass)#18 (8) 
        { 
            ["message"]=> string(6) "Vhhj99" 
            ["messageId"]=> int(1) 
            ["recipients"]=> string(11) "94714369777" 
            ["retries"]=> int(1) 
            ["sender"]=> object(stdClass)#19 (1) 
                { 
                    ["alias"]=> string(11) "94710200542" 
                } 
            ["sequenceNum"]=> int(1) 
            ["status"]=> int(1) 
            ["time"]=> string(25) "2018-10-13T10:40:24+05:30" 
        } 
} 

标签: phpweb

解决方案


使用 -> 运算符读取对象值

foreach($array as $key => $value){
  $message = $value->message;
}

推荐阅读