<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.math.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.min.php',
    1 => 'min',
    2 => 'Find lowest value',
  ),
  'up' => 
  array (
    0 => 'ref.math.php',
    1 => 'Math Functions',
  ),
  'prev' => 
  array (
    0 => 'function.max.php',
    1 => 'max',
  ),
  'next' => 
  array (
    0 => 'function.octdec.php',
    1 => 'octdec',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/math/functions/min.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.min" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">min</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">min</span> &mdash; <span class="dc-title">Find lowest value</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.min-description">
  <h3 class="title">Description</h3>
   <div class="methodsynopsis dc-description">
    <span class="methodname"><strong>min</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">...$values</code></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>

   <p class="simpara">Alternative signature (not supported with named arguments):</p>
   <div class="methodsynopsis dc-description"><span class="methodname"><strong>min</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$value_array</code></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>

  <p class="para rdfs-comment">
   If the first and only parameter is an array, <span class="function"><strong>min()</strong></span>
   returns the lowest value in that array. If at least two parameters are 
   provided, <span class="function"><strong>min()</strong></span> returns the smallest of these values.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Values of different types will be compared using the <a href="language.operators.comparison.php" class="link">
    standard comparison rules</a>. For instance, a non-numeric <span class="type"><a href="language.types.string.php" class="type string">string</a></span> will be
    compared to an <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> as though it were <code class="literal">0</code>, but multiple non-numeric
    <span class="type"><a href="language.types.string.php" class="type string">string</a></span> values will be compared alphanumerically. The actual value returned will be of the
    original type with no conversion applied.
   </p>
  </p></blockquote>
  <div class="caution"><strong class="caution">Caution</strong>
   <p class="simpara">
    Be careful when passing arguments of different types because
    <span class="function"><strong>min()</strong></span> can produce unpredictable results.
   </p>
  </div>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.min-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       Any <a href="language.operators.comparison.php" class="link">comparable</a>
       value.
      </p>
     </dd>
    
    
     <dt><code class="parameter">values</code></dt>
     <dd>
      <p class="para">
       Any <a href="language.operators.comparison.php" class="link">comparable</a>
       values.
      </p>
     </dd>
    
    
     <dt><code class="parameter">value_array</code></dt>
     <dd>
      <p class="para">
       An array containing the values.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.min-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   <span class="function"><strong>min()</strong></span> returns the parameter value considered &quot;lowest&quot; according to standard
   comparisons. If multiple values of different types evaluate as equal (e.g. <code class="literal">0</code>
   and <code class="literal">&#039;abc&#039;</code>) the first provided to the function will be returned.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.min-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   If an empty array is passed, <span class="function"><strong>min()</strong></span> throws a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.min-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <span class="function"><strong>min()</strong></span> throws a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> on failure now;
       previously, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> was returned and an <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> error was emitted.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       As <a href="migration80.incompatible.php#migration80.incompatible.core.string-number-comparision" class="link">
       string to number comparisons</a> were changed,
       <span class="function"><strong>min()</strong></span> no longer returns a
       different value based on the argument order in those cases.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.min-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Example uses of <span class="function"><strong>min()</strong></span></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">min</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #0000BB">3</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">6</span><span style="color: #007700">, </span><span style="color: #0000BB">7</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;  </span><span style="color: #FF8000">// 1<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">min</span><span style="color: #007700">(array(</span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #0000BB">4</span><span style="color: #007700">, </span><span style="color: #0000BB">5</span><span style="color: #007700">)), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">; </span><span style="color: #FF8000">// 2<br /><br />// Here we are comparing -1 &lt; 0, so -1 is the lowest value<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">min</span><span style="color: #007700">(</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">, -</span><span style="color: #0000BB">1</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;    </span><span style="color: #FF8000">// -1<br /><br />// With multiple arrays of different lengths, min returns the shortest<br /></span><span style="color: #0000BB">$val </span><span style="color: #007700">= </span><span style="color: #0000BB">min</span><span style="color: #007700">(array(</span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">), array(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">)); </span><span style="color: #FF8000">// array(2, 2, 2)<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$val</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Multiple arrays of the same length are compared from left to right<br />// so in our example: 2 == 2, but 4 &lt; 5<br /></span><span style="color: #0000BB">$val </span><span style="color: #007700">= </span><span style="color: #0000BB">min</span><span style="color: #007700">(array(</span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #0000BB">4</span><span style="color: #007700">, </span><span style="color: #0000BB">8</span><span style="color: #007700">), array(</span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #0000BB">5</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">)); </span><span style="color: #FF8000">// array(2, 4, 8)<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$val</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// If both an array and non-array are given, the array is never returned<br />// as comparisons treat arrays as greater than any other value<br /></span><span style="color: #0000BB">$val </span><span style="color: #007700">= </span><span style="color: #0000BB">min</span><span style="color: #007700">(</span><span style="color: #DD0000">'string'</span><span style="color: #007700">, array(</span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #0000BB">5</span><span style="color: #007700">, </span><span style="color: #0000BB">7</span><span style="color: #007700">), </span><span style="color: #0000BB">42</span><span style="color: #007700">);   </span><span style="color: #FF8000">// string<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$val</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// If one argument is NULL or a boolean, it will be compared against<br />// other values using the rules FALSE &lt; TRUE and NULL == FALSE regardless of the <br />// other types involved<br />// In the below examples, both -10 and 10 are treated as TRUE in the comparison<br /></span><span style="color: #0000BB">$val </span><span style="color: #007700">= </span><span style="color: #0000BB">min</span><span style="color: #007700">(-</span><span style="color: #0000BB">10</span><span style="color: #007700">, </span><span style="color: #0000BB">FALSE</span><span style="color: #007700">, </span><span style="color: #0000BB">10</span><span style="color: #007700">); </span><span style="color: #FF8000">// FALSE<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$val</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$val </span><span style="color: #007700">= </span><span style="color: #0000BB">min</span><span style="color: #007700">(-</span><span style="color: #0000BB">10</span><span style="color: #007700">, </span><span style="color: #0000BB">NULL</span><span style="color: #007700">, </span><span style="color: #0000BB">10</span><span style="color: #007700">);  </span><span style="color: #FF8000">// NULL<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$val</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// 0, on the other hand, is treated as FALSE, so is "lower than" TRUE<br /></span><span style="color: #0000BB">$val </span><span style="color: #007700">= </span><span style="color: #0000BB">min</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">TRUE</span><span style="color: #007700">); </span><span style="color: #FF8000">// 0<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$val</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>

 </div>

 <div class="refsect1 seealso" id="refsect1-function.min-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.max.php" class="function" rel="rdfs-seeAlso">max()</a> - Find highest value</span></li>
    <li><span class="function"><a href="function.count.php" class="function" rel="rdfs-seeAlso">count()</a> - Counts all elements in an array or in a Countable object</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>