php - 我如何阅读这个对象的内容
问题描述
我正在用 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"
}
}
解决方案
使用 -> 运算符读取对象值
foreach($array as $key => $value){
$message = $value->message;
}
推荐阅读
- reactjs - 元素隐式具有“任何”类型,因为“任何”类型的表达式不能用于索引类型“{ 1:元素; 2:元素;3:元素;}'。TS7053
- python - 子集到多个数据框并为每个数据框添加一个新列
- python - Google Search Crawler 和 Newspaper3k 库已在一个循环中组合,以创建自动抓取工具。但是代码不起作用..解决方案?
- visual-studio - 如何在 Visual Studio 中从 WiX 自定义操作创建 Nuget 包
- location - 我如何在电报内的内联键盘中请求用户的位置?
- python - 使用已覆盖注意力头的 BART 编码器运行拥抱脸 BART 模型解码器
- ssis - 在 Visual Studio 2019 中创建的 SSIS 无法在 Visual Studio 2010 中创建的应用程序中运行
- git - 如果在一个分支上完成并将功能合并到该分支中,工作是否会被覆盖?
- reactjs - 如何从保存在本地存储中的数组中删除项目?
- python - 给定一个文本文件,每行都有一个字符串列表,如何将每个列表附加到 python 中的一个大列表中