Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 4067

php-manual-en-5.5.7-1.mga4.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 highest value</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.log.html">log</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.min.html">min</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.max" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">max</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">max</span> &mdash; <span class="dc-title">Find highest value</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.max-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>max</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>max</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>max()</strong></span>
   returns the highest value in that array. If at least two parameters are 
   provided,  <span class="function"><strong>max()</strong></span> returns the biggest of these values.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    PHP will evaluate a non-numeric <span class="type"><a href="language.types.string.html" class="type string">string</a></span> as 
    <em>0</em> if compared to <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>, but still return the string if it&#039;s seen as the
    numerically highest value.  If multiple arguments evaluate to
    <em>0</em>,  <span class="function"><strong>max()</strong></span> will return a numeric
    <em>0</em> if given, else the alphabetical highest string
    value will be returned.
   </p>
  </p></blockquote>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.max-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">values</code></em></span>
     <dd>

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

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">value1</code></em></span>
     <dd>

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

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">value2</code></em></span>
     <dd>

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

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">...</code></em></span>
     <dd>

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

    </dt>

   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.max-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
    <span class="function"><strong>max()</strong></span> returns the numerically highest of the
   parameter values. If multiple values can be considered of the same size,
   the one that is listed first will be returned.
  </p>
  <p class="para">
   When  <span class="function"><strong>max()</strong></span> is given multiple <span class="type"><a href="language.types.array.html" class="type array">array</a></span>s, the
   longest array is returned. If all the arrays have the same length,
    <span class="function"><strong>max()</strong></span> will use lexicographic ordering to find the return
   value.
  </p>
  <p class="para">
   When given a <span class="type"><a href="language.types.string.html" class="type string">string</a></span> it will be cast as an <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>
   when comparing.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.max-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-3463">
    <p><strong>Example #1 Example uses of  <span class="function"><strong>max()</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">max</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</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;7<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">max</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;5<br /><br />//&nbsp;When&nbsp;'hello'&nbsp;is&nbsp;cast&nbsp;as&nbsp;integer&nbsp;it&nbsp;will&nbsp;be&nbsp;0.&nbsp;Both&nbsp;the&nbsp;parameters&nbsp;are&nbsp;equally<br />//&nbsp;long,&nbsp;so&nbsp;the&nbsp;order&nbsp;they&nbsp;are&nbsp;given&nbsp;in&nbsp;determines&nbsp;the&nbsp;result<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">max</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">max</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 /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">max</span><span style="color: #007700">(</span><span style="color: #DD0000">'42'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;'42'<br /><br />//&nbsp;Here&nbsp;0&nbsp;&gt;&nbsp;-1,&nbsp;so&nbsp;'hello'&nbsp;is&nbsp;the&nbsp;return&nbsp;value.<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">max</span><span style="color: #007700">(-</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;hello<br /><br />//&nbsp;With&nbsp;multiple&nbsp;arrays&nbsp;of&nbsp;different&nbsp;lengths,&nbsp;max&nbsp;returns&nbsp;the&nbsp;longest<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">max</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(1,&nbsp;1,&nbsp;1,&nbsp;1)<br /><br />//&nbsp;With&nbsp;multiple&nbsp;arrays&nbsp;of&nbsp;the&nbsp;same&nbsp;length,&nbsp;max&nbsp;compares&nbsp;from&nbsp;left&nbsp;to&nbsp;right<br />//&nbsp;using&nbsp;lexicographic&nbsp;order,&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">max</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">7</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;array(2,&nbsp;5,&nbsp;7)<br /><br />//&nbsp;If&nbsp;both&nbsp;an&nbsp;array&nbsp;and&nbsp;non-array&nbsp;are&nbsp;given,&nbsp;the&nbsp;array<br />//&nbsp;is&nbsp;always&nbsp;returned&nbsp;as&nbsp;it's&nbsp;seen&nbsp;as&nbsp;the&nbsp;largest<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">max</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;array(2,&nbsp;5,&nbsp;7)<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    </div> 
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.max-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.min.html" class="function" rel="rdfs-seeAlso">min()</a> - Find lowest 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.log.html">log</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.min.html">min</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>