这是一个愚蠢的问题,但我无法弄清楚为什么我的指针功能不起作用。为什么他们不工作?
$r = array("boo", "goo", "buzz");
while($r = current($r))
{
echo $r . '<br />';
next($r);
}
答案 0 :(得分:2)
在while上删除该作业:
示例:
$r = array("boo", "goo", "buzz");
while(current($r)) { // get current until true so it will loop, dont assign, you will overwrite r (the array), you could assign a new variable name instead, then use that new name to echo
echo current($r) . '<br />'; // echo current pointer, not the whole array
next($r); // shift to next pointer
}
或
$r = array("boo", "goo", "buzz");
while($a = current($r)) { // now you can assign, you won't overwrite `$r`
echo $a . '<br />';
next($r); // move to next pointer in r
}
答案 1 :(得分:0)
试试这种方式。
$r = array("boo", "goo", "buzz");
while(list($var, $val) = each($r))
{
echo $val . '<br />';
}