July 13, 201115 yr Hey guys. I´m trying to write down a random number function. However the number 5 must evulate to "great"; I just can't seem to get it to work correctly. I want to do (mt_rand(0,6)) and once it hits 5 that it should evaluate to "great". I can't get it to work even with the use of if and else. Perhaps some'one can plain me a bit more?
July 13, 201115 yr Hey guys. I´m trying to write down a random number function. However the number 5 must evulate to "great"; I just can't seem to get it to work correctly. I want to do (mt_rand(0,6)) and once it hits 5 that it should evaluate to "great". I can't get it to work even with the use of if and else. Perhaps some'one can plain me a bit more? A quick and dirty solution: $number = rand(1,6); $value = ""; if($number == 1) $value = "one"; elseif($number == 2) $value = "two"; elseif($number == 3) $value = "three"; elseif($number == 4) $value = "four"; elseif($number == 5) $value = "great"; elseif($number == 6) $value = "six"; echo $value; Hope that helped! Edited July 13, 201115 yr by TomCash
July 13, 201115 yr Author ah thanks I didn't knew you could target functions in this way, thanks a lot I will remember this one. +1 for you.
Create an account or sign in to comment