Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Array of whole numbers
- $array = array(25, 23, 4, 56, 257);
- try {
- echo getMinValue($array);
- } catch(Exception $e) {
- echo $e->getMessage();
- }
- // Custom function that returns minimum value of an array
- function getMinValue($array) {
- if(empty($array)) {
- throw new Exception("No values in array");
- }
- $min = $array[0];
- foreach($array as $key => $val) {
- if($min > $val) {
- $min = $val;
- }
- }
- return $min;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement