Set a minimum value


/ Published in: PHP
Save to your folder(s)

Method takes the amount and compares with the lowest/highest value and assigns that variable with the lowest/highest value. Good for setting the bar for lowest/highest value found in a set of value.


Copy this code and paste it in your HTML
  1. function check_max($value1, $value2) {
  2. if ((float)$value2 > (float)$value1) $max = (float)$value2;
  3. else $max = (float)$value1;
  4. return $max;
  5. }
  6.  
  7. function check_min($value1, $value2) {
  8. if ($value2 != 0) {
  9. //dump(array($value1,$value2));
  10. if ((float)$value2 < (float)$value1) $min = (float)$value2;
  11. else $min = (float)$value1;
  12. return $min;
  13. } else return $value1;
  14. }
  15.  
  16.  
  17. //usage:
  18. $max = check_max($max, $value_to_compare);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.