无法访问我的数组中的值

时间:2012-08-10 13:28:28

标签: php arrays

我有一个数组:

$response['ids']

var_dump($response['ids']);

给了我这个结果:

array(849) { [0]=> int(75740521) [1]=> int(148743815) [2]=> int(14135942) [3]=> int(516369973) [4]=> int(18667319)

因此,我尝试使用此例程获取这些值:

$i=0;
while($i <= $nrof){ 
    $friendsid = $friends['ids'][$i];
    echo "Friend $i-id: $friendsid<br />";
    $i++;
}

但我没有得到任何价值,$friends['ids'][$i]总是空的。

4 个答案:

答案 0 :(得分:4)

你是var_dumping $response但是正在循环$friends

答案 1 :(得分:4)

尝试将$ friends更改为$ response

答案 2 :(得分:2)

你为什么var_dump $ 回复 ['ids']但是,在你的代码中使用$ 朋友 ['ids']?

答案 3 :(得分:2)

尝试使用foreach:

foreach ($friends['ids'] as $key => $value)
{
    echo "Friend $key-id: $value<br />";
}

http://php.net/manual/en/control-structures.foreach.php

相关问题