求助,遍历数组
有这样一个数组
我现在可以得到data数组
方法为
$data->data
而现在我要循环遍历出data下面的数据。我用for
有这种形式,但是失败的
$data->data->$i->zqdm
还请高手指点一下。
原数组为
PHP code
stdClass Object
(
[totalPages] => 30
[p] => 1
[totalCount] => 299
[data] => Array
(
[0] => stdClass Object
(
[uin] => 843035290
[grpId] => 0
[jydm] =>
[zqdm] => 600251
[zqjc] => 鍐犲啘鑲′唤
[type] => s
[cbj] => 21.97
[amount] => 1000
[date] => 2011-12-09 09:32:41
)
[1] => stdClass Object
(
[uin] => 843035290
[grpId] => 0
[jydm] =>
[zqdm] => 600251
[zqjc] => 鍐犲啘鑲′唤
[type] => b
[cbj] => 22.29
[amount] => 1000
[date] => 2011-12-08 14:34:08
)
[2] => stdClass Object
(
[uin] => 843035290
[grpId] => 0
[jydm] =>
[zqdm] => 600537
[zqjc] => 娴烽€氶泦鍥? [type] => s
[cbj] => 21.6
[amount] => 1000
[date] => 2011-12-08 13:00:24
)
)
)
------解决方案--------------------不知道你在说什么
------解决方案-------------------- [data] => Array
(
[0] => stdClass Object
请注意:data是数组
$data->data[$i]->zqdm
------解决方案--------------------$data->data[$i]->zqdm 这样
------解决方案--------------------用foreach $data->data as $k=>$v试试, 手册中simpleXML能找到相关信息.
------解决方案--------------------除非你给出了错误数据
PHP code
$d->data[2]->x = 'abcd';
print_r($d);
echo $d->data[2]->x;
------解决方案--------------------
------解决方案--------------------
foreach($data->data as $k=>$v){
echo $k.' => '.$v.'<br/>';
}
------解决方案--------------------
不是echo, 用print_r
------解决方案--------------------
------解决方案--------------------
语法错误,意想不到的T_EXIT,期待T_FUNCTION ???
你只给程序片段,如何知道错在哪里?