There are dynamic data from the user, which on the server must be checked for occurrence in a particular range and, depending on this, output a different result.

It only occurs to me (conditional example):

if($var < 1000) { do one } else if ($var < 2000) { do two } else if ($var < 3000) { do three } .... и т.д. 

Tell me how to simplify this design?

  • @ Ipatiev where is it? Example conditional, for ease of understanding the essence of the problem - humster_spb
  • one
    Well, in this simplified version - not to reduce. and if you know how the result is calculated, then you can. and in this case, the knowledge gained in the second grade will be useful - Ipatiev
  • @ Ipatiev doesn’t calculate anything: the user enters data, they are compared with a range - humster_spb

1 answer 1

Since the author for some reason stubbornly does not recognize what kind of result he needs to derive, will have to fantasize.

In case you just need to display some text, such knowledge from the elementary school course as division and rounding will be useful to us.

 $results = [ "Герой пионерского лагеря", "Дважды герой пионерского лагеря", "Многократный призер куличиков и совочка", ] $place = floor($var / 1000); echo $results[$place] ?? 'Завхоз по наградам'; 
  • one
    Well, but you can't skip $results[$place] ?? 'Завхоз по наградам' $results[$place] ?? 'Завхоз по наградам' Steward Farm $results[$place] ?? 'Завхоз по наградам' - vp_arth
  • Here! Works. Thank! - humster_spb