php max () min () Returns the maximum and minimum values

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags array echo network network programming php php tutorial programming return

max () returns the maximum value.

grammar
max (x, y) Parameter Description
x Required. A few.
y necessary. A few.

Description
max () Returns the value with the highest value in the argument.

If there is only one parameter and an array, max () returns the largest value in the array. If the first argument is an integer, string, or floating point number, at least two arguments are required and max () returns the largest of these values. You can compare an unlimited number of values.

echo max (1,3,5,6,7); // returns 7
echo "<br>";
echo max (array (2,4,5)); // returns 5
echo "<br>";
echo max (0, 'hello'); // returns 0
echo "<br>";
echo max ('hello', 0); // return hello
echo "<br>";
echo max (-1, 'hello'); // return hello
echo "<br>";
$ val = max (array (2,4,8), array (2,5,7)); // returns the second array
print_r ($ val);
echo "<br>";
$ val = max ('string', array (2,5,7), 42); // returns an array

print_r ($ val);
/ *
min () returns the minimum value.

grammar
min (x, y) Parameter Description
x Required. A few.
y necessary. A few.

Description
min () Returns the smallest value in the argument.

If there is only one argument and an array, min () returns the smallest value in the array. If the first argument is an integer, string, or floating point number, at least two arguments are required and min () returns the smallest of those values. You can compare an unlimited number of values

* /

echo min (2,3,1,6,7); // 1
echo "<br>";
echo min (array (2,4,5)); // 2
echo "<br>";
echo min (0, 'hello'); // 0
echo "<br>";
echo min ('hello', 0); // hello
echo "<br>";
echo min ('hello', - 1); // - 1
echo "<br>";
$ val = min (array (2,4,8), array (2,5,1)); // returns the first array
print_r ($ val);
echo "<br>";
$ val = min ('string', array (2,5,7), 42); // return string
print_r ($ val);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.