我在这些对象中获取数组时遇到了一些问题。当我 print_r() 时,会打印以下代码。$message_object 是对象的名称。
SimpleXMLElement Object
(
[header] => SimpleXMLElement Object
(
[responsetime] => 2012-12-22T14:10:09+00:00
)
[data] => SimpleXMLElement Object
(
[id] => Array
(
[0] => 65233
[1] => 65234
)
[account] => Array
(
[0] => 20992
[1] => 20992
)
[shortcode] => Array
(
[0] => 3255
[1] => 3255
)
[received] => Array
(
[0] => 2012-12-22T11:04:30+00:00
[1] => 2012-12-22T11:31:08+00:00
)
[from] => Array
(
[0] => 6121843347
[1] => 6121820166
)
[cnt] => Array
(
[0] => 24
[1] => 25
)
[message] => Array
(
[0] => Go tramping wellington 11-30
[1] => Go drinking Matakana 2pm
)
)
)
我正在尝试使用 foreach 从对象中获取 id 数组:
foreach($message_object->data->id AS $id) {
print_r($id);
}
发送以下回复:
SimpleXMLElement Object ( [0] => 65233 ) SimpleXMLElement Object ( [0] => 65234 )
我如何获得 [0] 的值,还是我要解决这个问题?有没有办法循环遍历结果并获取对象键?
我试图回显 $id[0] 但它没有返回任何结果。