Random number output problem $ randnumber = rand (); switch ($ randnumber) {case1: echo & quot; 1 & quot; break; case2: echo & quot; 2 & quot; break; case3: echo & quot; 3 & quot; brea random number output problem
$ 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 ";
}
Ask, why is the above output result changing between 1 and 4? why is it not a fixed value?
------ Solution --------------------
If it is fixed, it is not a random number.
------ Solution --------------------
What do you want? Discussion
$ 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 ";
}
Ask, the above output ......
------ Solution --------------------
Every time you refresh, it will change.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.