Figured I would keep up the trend of talking about finding the smallest and largest values in arrays by talking about finding the smallest or largest value in a set of values. Incidentally, doing so will utilize the same min() and max() functions we used previously. Not one of my favorite things, but PHP has a tendency to allow mixed input on some functions. In this case, min() and max() can take either a single array of input or a series of values (which could be an array). If more than one argument is present, the functions will determine the smallest or largest value from the passed arguments.

// Finds the smallest value
$smallest = min('one', 50, false, array(1,2,3));

// Finds the largest value
$largest = max('BIG', 'little', 3.14, true, $val);

Also keep in mind that this technique is good for obtaining the smallest or largest value but doesn’t do much for control flow. For that, you’d still want to utilize if/else control structures.





Did you enjoy this post?

Cool if I slip into your inbox with more?
Full posts, 1-2 times per week: