$units = array(
"R" =>"Kid Pan", "PO Krillen", "Android #16", "Android #19",
'SR'=>'Vegeta', 'Piccolo', 'Botamo', 'SSJ2GokuGT', 'CaptainGinyu',
'SSR'=>'TEQPerfectCell', 'STRGogeta', 'PHYKidBuu', 'STRBroly',
);
echo $units[rand(0, count($units) - 1)] . "\n";
这段代码可以正常工作,但有时会出错,有些带有不同的网络号?
例如; “NOTICE undefined offset :第8行上为10” 和注意 undefined offset :第8行上为
顺便说一句,我正在使用http://phptester.net/测试此代码
(我是菜鸟-对不起:/)
最佳答案
尝试使用array_rand
echo $units[ array_rand($units)] . "\n";
http://php.net/manual/en/function.array-rand.php
关于php - 随机变量时 undefined offset ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48130573/