Krch there is for example such code:

$a = rand(1.100); $b = rand(1.100); if ($a ==$b) { echo "Вы победили"; 

How to make it so that the condition is met if the spread of numbers, for example, 10, that is, if $ a = 40, and $ b = 50 or $ b = 49, etc., then did it also show that I won? Maybe there is a special function for this?

  • you have an error in the code: rand(1.100); what does it even mean? rand takes either 2 parameters or zero parameters - strangeqargo
  • I know, there should be a comma, even Shift did not complain. And not the essence of the code. - The Cold

1 answer 1

Obviously, calculate the difference and compare with 10 (without taking into account the sign):

 if( abs($a - $b) <= 10 ) { echo "Вы победили"; } 

PS Only first, correctly rand() should be called, and not like yours.

  • And how in the next if further make the spread from 11 to 20? - The Cold
  • @gottar rand already deprecated, better mt_rand - strangeqargo
  • @TheCold, uh ... didn’t quite understand what was stopping to check if the difference falls in the range from 11 to 20? - gottar
  • @TheCold to make a composite condition for the difference modulus to be from 11 to 20. - Vladimir Martyanov
  • Damn, I'm dumbing something scary. Did already. Thanks to all. - The Cold