Math min

(PHP 4, PHP 5, PHP 7, PHP 8)

min — Find lowest value


설명

min(mixed $value, mixed ...$value): mixed

Alternative signature (not supported with named arguments):

min(array $value_array): mixed

첫 번째이자 유일한 매개변수가 배열인 경우 min()은 해당 배열에서 가장 낮은 값을 반환합니다. 두 개 이상의 매개변수가 제공되면 min()은 이러한 값 중 가장 작은 값을 반환합니다.

메모: 다른 유형의 값은 표준 비교 규칙을 사용하여 비교됩니다. 예를 들어 숫자가 아닌 문자열은 0인 것처럼 int와 비교되지만 숫자가 아닌 여러 문자열 값은 영숫자 순으로 비교됩니다. 반환된 실제 값은 변환이 적용되지 않은 원래 유형입니다.

주의 min()이 예측할 수 없는 결과를 생성할 수 있으므로 다른 유형의 인수를 전달할 때 주의하십시오.


매개변수

value
Any comparable value.
values
Any comparable value.
value_array
An array containing the values.

반환 값

min()은 표준 비교에 따라 "lowest"로 간주되는 매개변수 값을 반환합니다. 다른 유형의 여러 값이 동일한 것으로 평가되는 경우(예: 0'abc') 함수에 제공된 첫 번째 값이 반환됩니다.

빈 배열이 전달되면 false가 반환되고 E_WARNING 오류가 발생합니다.


Examples

예제 #1 min() 사용 예

                  
<?php
echo min(2, 3, 1, 6, 7);  // 1
echo min(array(2, 4, 5)); // 2

// The string 'hello' when compared to an int is treated as 0
// Since the two values are equal, the order they are provided determines the result
echo min(0, 'hello');     // 0
echo min('hello', 0);     // hello

// Here we are comparing -1 < 0, so -1 is the lowest value
echo min('hello', -1);    // -1

// With multiple arrays of different lengths, min returns the shortest
$val = min(array(2, 2, 2), array(1, 1, 1, 1)); // array(2, 2, 2)

// Multiple arrays of the same length are compared from left to right
// so in our example: 2 == 2, but 4 < 5
$val = min(array(2, 4, 8), array(2, 5, 1)); // array(2, 4, 8)

// If both an array and non-array are given, the array is never returned
// as comparisons treat arrays as greater than any other value
$val = min('string', array(2, 5, 7), 42);   // string

// If one argument is NULL or a boolean, it will be compared against
// other values using the rules FALSE < TRUE and NULL == FALSE regardless of the
// other types involved
// In the below examples, both -10 and 10 are treated as TRUE in the comparison
$val = min(-10, FALSE, 10); // FALSE
$val = min(-10, NULL, 10);  // NULL

// 0, on the other hand, is treated as FALSE, so is "lower than" TRUE
$val = min(0, TRUE); // 0
?>
                  
                

기타

  • max() - Find highest value
  • count() - Counts all elements in an array or in a Countable object