Home > Backend Development > PHP Tutorial > 随机数输出有关问题

随机数输出有关问题

WBOY
Release: 2016-06-13 13:06:47
Original
840 people have browsed it

随机数输出问题
$randnumber=rand(1,4);
switch ($randnumber)
{
case 1:
echo "1";
break;
case 2:
echo "2";
break;
case 3:
echo "3";
break;
case 4:
echo "4";
break;
default:
 echo "0";

}

请教,以上的输出结果在1-4之间变幻,为什么不是一个固定值呢


------解决方案--------------------
固定了就不是随机数了
------解决方案--------------------
你想干嘛呢?

探讨
$randnumber=rand(1,4);
switch ($randnumber)
{
case 1:
echo "1";
break;
case 2:
echo "2";
break;
case 3:
echo "3";
break;
case 4:
echo "4";
break;
default:
echo "0";

}

请教,以上的输出结果……

------解决方案--------------------
你每次刷新就会变化
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template