Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

must contain at least one element

Description

min() and max() only work on arrays that contains at least one element. The object here is to avoid the confusion of the null value that may be the result of the operation, and the null that PHP used to return when there was nothing to process in the array.

Example

<?php

echo min([]);
echo max([]);

?>

Alternatives

  • Check for empty() before using the min() or max() functions.