Php max () min () returns the maximum and minimum values

Source: Internet
Author: User

 

Max () returns the maximum value.

Syntax
Max (x, y) parameter description
X is required. A number.
Y is required. A number.

Description
Max () returns the maximum value in the parameter.

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

Echo max (, 7); // return 7
Echo"
";
Echo max (array (2, 4, 5); // returns 5
Echo"
";
Echo max (0, 'Hello'); // return 0
Echo"
";
Echo max ('hello', 0); // return hello
Echo"
";
Echo max (-1, 'Hello'); // return hello
Echo"
";
$ Val = max (array (2, 4, 8), array (2, 5, 7); // returns the second array
Print_r ($ val );
Echo"
";
$ Val = max ('string', array (, 7), 42); // returns an array

Print_r ($ val );

/*
Min () returns the minimum value.

Syntax
Min (x, y) parameter description
X is required. A number.
Y is required. A number.

Description
Min () returns the smallest value in the parameter.

If there is only one parameter and it is an array, min () returns the smallest value in the array. If the first parameter is an integer, string, or floating point number, at least two parameters are required and min () returns the smallest of these values. You can compare an infinite number of values.

*/

Echo min (2, 3, 1, 6, 7); // 1
Echo"
";
Echo min (array (2, 4, 5); // 2
Echo"
";
Echo min (0, 'Hello'); // 0
Echo"
";
Echo min ('hello', 0); // hello
Echo"
";
Echo min ('hello',-1); //-1
Echo"
";
$ Val = min (array (, 8), array (, 1); // returns the first array
Print_r ($ val );
Echo"
";
$ Val = min ('string', array (, 7), 42); // return string
Print_r ($ val );


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.