Sophie

Sophie

distrib > Mageia > 7 > armv7hl > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 4741

php-manual-en-7.2.11-1.mga7.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Find lowest value</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.max.html">max</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mt-getrandmax.html">mt_getrandmax</a></div>
 <div class="up"><a href="ref.math.html">Math Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.min" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">min</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</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="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>min</strong></span>
     ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$values</code></span>
    )</div>

   <div class="methodsynopsis dc-description">
    <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>min</strong></span>
     ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value1</code></span>
    , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value2</code></span>
    [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$...</code></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.html" class="link">
    standard comparison rules</a>. For instance, a non-numeric <span class="type"><a href="language.types.string.html" class="type string">string</a></span> will be
    compared to an <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span> as though it were <em>0</em>, but multiple non-numeric
    <span class="type"><a href="language.types.string.html" 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 with mixed types values 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">values</code></dt>

     <dd>

      <p class="para">
       An array containing the values.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">value1</code></dt>

     <dd>

      <p class="para">
       Any <a href="language.operators.comparison.html" class="link">comparable</a>
       value.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">value2</code></dt>

     <dd>

      <p class="para">
       Any <a href="language.operators.comparison.html" class="link">comparable</a>
       value.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">...</code></dt>

     <dd>

      <p class="para">
       Any <a href="language.operators.comparison.html" class="link">comparable</a>
       value.
      </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. <em>0</em>
   and <em>&#039;abc&#039;</em>) the first provided to the function will be returned.
  </p>

  <p class="para">
   If an empty array is passed, then <strong><code>FALSE</code></strong> will be returned and an
   <strong><code>E_WARNING</code></strong> error will be emitted.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.min-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-4261">
    <p><strong>Example #1 Example uses of <span class="function"><strong>min()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">6</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">7</span><span style="color: #007700">);&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;1<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(array(</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;2<br /><br />//&nbsp;The&nbsp;string&nbsp;'hello'&nbsp;when&nbsp;compared&nbsp;to&nbsp;an&nbsp;int&nbsp;is&nbsp;treated&nbsp;as&nbsp;0<br />//&nbsp;Since&nbsp;the&nbsp;two&nbsp;values&nbsp;are&nbsp;equal,&nbsp;the&nbsp;order&nbsp;they&nbsp;are&nbsp;provided&nbsp;determines&nbsp;the&nbsp;result<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;0<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;hello<br /><br />//&nbsp;Here&nbsp;we&nbsp;are&nbsp;comparing&nbsp;-1&nbsp;&lt;&nbsp;0,&nbsp;so&nbsp;-1&nbsp;is&nbsp;the&nbsp;lowest&nbsp;value<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">,&nbsp;-</span><span style="color: #0000BB">1</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;-1<br /><br />//&nbsp;With&nbsp;multiple&nbsp;arrays&nbsp;of&nbsp;different&nbsp;lengths,&nbsp;min&nbsp;returns&nbsp;the&nbsp;shortest<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(array(</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">),&nbsp;array(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;array(2,&nbsp;2,&nbsp;2)<br /><br />//&nbsp;Multiple&nbsp;arrays&nbsp;of&nbsp;the&nbsp;same&nbsp;length&nbsp;are&nbsp;compared&nbsp;from&nbsp;left&nbsp;to&nbsp;right<br />//&nbsp;so&nbsp;in&nbsp;our&nbsp;example:&nbsp;2&nbsp;==&nbsp;2,&nbsp;but&nbsp;4&nbsp;&lt;&nbsp;5<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(array(</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">8</span><span style="color: #007700">),&nbsp;array(</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;array(2,&nbsp;4,&nbsp;8)<br /><br />//&nbsp;If&nbsp;both&nbsp;an&nbsp;array&nbsp;and&nbsp;non-array&nbsp;are&nbsp;given,&nbsp;the&nbsp;array&nbsp;is&nbsp;never&nbsp;returned<br />//&nbsp;as&nbsp;comparisons&nbsp;treat&nbsp;arrays&nbsp;as&nbsp;greater&nbsp;than&nbsp;any&nbsp;other&nbsp;value<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(</span><span style="color: #DD0000">'string'</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">7</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">42</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;string<br /><br />//&nbsp;If&nbsp;one&nbsp;argument&nbsp;is&nbsp;NULL&nbsp;or&nbsp;a&nbsp;boolean,&nbsp;it&nbsp;will&nbsp;be&nbsp;compared&nbsp;against<br />//&nbsp;other&nbsp;values&nbsp;using&nbsp;the&nbsp;rules&nbsp;FALSE&nbsp;&lt;&nbsp;TRUE&nbsp;and&nbsp;NULL&nbsp;==&nbsp;FALSE&nbsp;regardless&nbsp;of&nbsp;the&nbsp;<br />//&nbsp;other&nbsp;types&nbsp;involved<br />//&nbsp;In&nbsp;the&nbsp;below&nbsp;examples,&nbsp;both&nbsp;-10&nbsp;and&nbsp;10&nbsp;are&nbsp;treated&nbsp;as&nbsp;TRUE&nbsp;in&nbsp;the&nbsp;comparison<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(-</span><span style="color: #0000BB">10</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;FALSE<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(-</span><span style="color: #0000BB">10</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">);&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;NULL<br /><br />//&nbsp;0,&nbsp;on&nbsp;the&nbsp;other&nbsp;hand,&nbsp;is&nbsp;treated&nbsp;as&nbsp;FALSE,&nbsp;so&nbsp;is&nbsp;"lower&nbsp;than"&nbsp;TRUE<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">TRUE</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;0<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 class="member"><span class="function"><a href="function.max.html" class="function" rel="rdfs-seeAlso">max()</a> - Find highest value</span></li>
    <li class="member"><span class="function"><a href="function.count.html" class="function" rel="rdfs-seeAlso">count()</a> - Count all elements in an array, or something in an object</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.max.html">max</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mt-getrandmax.html">mt_getrandmax</a></div>
 <div class="up"><a href="ref.math.html">Math Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>