Created
October 24, 2018 05:50
-
-
Save fyulistian/294a7db14a1066aeed93b349a7a450be to your computer and use it in GitHub Desktop.
Numeric range validator. Check the new value is available in the range or not with php.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // initialize | |
| $range = array(); | |
| $range_price = array(); | |
| // data range | |
| $range = array ( | |
| 0 => array ( | |
| "min_range" => 10000, | |
| "max_range" => 14000 | |
| ), | |
| 1 => array ( | |
| "min_range" => 15000, | |
| "max_range" => 17500 | |
| ) | |
| ); | |
| // get each range | |
| foreach ($range as $key => $value) { | |
| // initialize for minimum and maximum range | |
| $min_range = $value["min_range"] - 1; | |
| $max_range = $value["max_range"] + 1; | |
| // check the minimum and maximum range | |
| $new_start = min($max_range, max($min_range, $price_start)); | |
| $new_end = min($max_range, max($min_range, $price_end)); | |
| // check possibility | |
| $parameters = ($new_start === $new_end) ? 1 : 0; | |
| $range_price[] = $parameters; | |
| } | |
| // had possibility ? | |
| if (in_array(0, $range_price, true)) { | |
| $is_error = 1; | |
| $error_msg = "Range available."; | |
| } else { | |
| // doSomething | |
| // ... | |
| // ... | |
| // ... | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment