max

(PHP 4, PHP 5, PHP 7)

max锟揭筹拷锟斤拷锟街�

说锟斤拷

max ( array $values ) : mixed
max ( mixed $value1 , mixed $value2 [, mixed $... ] ) : mixed

锟斤拷锟斤拷锟斤拷锟揭伙拷锟斤拷锟斤拷锟斤拷锟轿拷锟斤拷椋�max() 锟斤拷锟截革拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷值锟斤拷锟斤拷锟斤拷锟揭伙拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷锟斤拷蚋〉锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟揭拷锟斤拷锟斤拷锟斤拷锟斤拷锟� max() 锟结返锟斤拷锟斤拷些值锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟皆比斤拷锟斤拷锟睫讹拷锟街碉拷锟�

Note:

PHP 锟结将锟斤拷锟斤拷值锟斤拷 string 锟斤拷锟斤拷 0锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷值锟斤拷锟斤拷然锟结返锟斤拷一锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷值为 0 锟斤拷锟斤拷锟斤拷锟街碉拷锟�max() 锟结返锟斤拷锟斤拷锟斤拷锟斤拷值锟斤拷 0锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟矫伙拷锟斤拷锟街碉拷锟� 0锟斤拷锟津返回帮拷锟斤拷母锟斤拷顺锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷

锟斤拷锟斤拷

values

锟斤拷锟斤拷锟剿讹拷锟街碉拷锟斤拷锟斤拷椤�

value1

Any comparable value.

value2

Any comparable value.

...

Any comparable value.

锟斤拷锟斤拷值

max() 锟斤拷锟截诧拷锟斤拷锟斤拷锟斤拷值锟斤拷锟斤拷值锟斤拷 If multiple values can be considered of the same size, the one that is listed first will be returned.

When max() is given multiple arrays, the longest array is returned. If all the arrays have the same length, max() will use lexicographic ordering to find the return value.

When given a string it will be cast as an integer when comparing.

锟斤拷锟斤拷

Example #1 使锟斤拷 max() 锟斤拷锟斤拷锟斤拷

<?php
echo max(13567);  // 7
echo max(array(245)); // 5

// When 'hello' is cast as integer it will be 0. Both the parameters are equally
// long, so the order they are given in determines the result
echo max(0'hello');     // 0
echo max('hello'0);     // hello

echo max('42'3); // '42'

// Here 0 > -1, so 'hello' is the return value.
echo max(-1'hello');    // hello

// With multiple arrays of different lengths, max returns the longest
$val max(array(222), array(1111)); // array(1, 1, 1, 1)

// 锟皆讹拷锟斤拷锟斤拷椋琺ax 锟斤拷锟斤拷锟斤拷锟揭比较★拷
   // 锟斤拷锟斤拷诒锟斤拷锟斤拷校锟�2 == 2锟斤拷锟斤拷 4 < 5
$val max(array(248), array(257)); // array(2, 5, 7)

// 锟斤拷锟酵憋拷锟斤拷锟斤拷锟斤拷锟酵凤拷锟斤拷锟斤拷锟斤拷为锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟角斤拷锟斤拷锟斤拷锟斤拷为
   // 锟斤拷锟街碉拷锟斤拷锟�
$val max('string', array(257), 42);   // array(2, 5, 7)
?>

锟轿硷拷

  • min() - 锟揭筹拷锟斤拷小值
  • count() - 锟斤拷锟斤拷锟斤拷锟斤拷锟叫的碉拷元锟斤拷目锟斤拷锟斤拷锟斤拷锟斤拷械锟斤拷锟斤拷愿锟斤拷锟�