为什么我的PHP代码不起作用?

Ste*_*ven 2 php mysql arrays shuffle

以下是代码:

function swap(&$a, &$b)
{
     list($a, $b) = array($b, $a);
}

for ($i=0; count($resultset);$i++)
{
    for($j=1;$j<5;$j++)
    {
         $k = rand(1, 4);
         swap($resultset[$i]["option".$j],$resultset[$i]["option".$k]); 
    }
}
Run Code Online (Sandbox Code Playgroud)

它是来自MySQL查询的二维数组,我想要将其键为option1,option2,option3和option4的值进行混洗.但我的代码不起作用.我自己可以找到错误.请建议.提前致谢!

mau*_*ris 11

刚看到它:

for ($i=0; count($resultset);$i++)
Run Code Online (Sandbox Code Playgroud)

不应该

for ($i=0; $i < count($resultset);$i++)
Run Code Online (Sandbox Code Playgroud)

你错过了for循环中的比较.