Random number output problem $ randnumberrand (); switch ($ randnumber) {case1: echo & quot; 1 & quot; break; case2: echo & quot; 2 & quot ;; break; case3: echo & quot; 3 & quot; break; case4: echo & quot; 4 & quot; break; 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.