编辑:是因为 $i 被初始化为 1 而不是 0...???
我将从数据库中检索到的某些值存储在会话变量中。我就是这样做的:
$i = 1;
//query to select tuples from the database;
while($i <= $num) //$num is the count of the rows returned by the query
{
$_SESSION['first'][$i] = $row->first;
$_SESSION['second'][$i] = $row->second;
$i++;
}
然后我按如下方式使用它们:
$i = 1;
foreach ($_SESSION['first'] as $names)
{
//do something with $_SESSION['second'][$i];
$i++;
}
我得到的错误:( 刷新页面后消失)
Invalid argument supplied for foreach()