<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.array.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.array-unique.php',
    1 => 'array_unique',
    2 => 'Removes duplicate values from an array',
  ),
  'up' => 
  array (
    0 => 'ref.array.php',
    1 => 'Функції для роботи з масивами',
  ),
  'prev' => 
  array (
    0 => 'function.array-uintersect-uassoc.php',
    1 => 'array_uintersect_uassoc',
  ),
  'next' => 
  array (
    0 => 'function.array-unshift.php',
    1 => 'array_unshift',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/array/functions/array-unique.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.array-unique" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">array_unique</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.1, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">array_unique</span> &mdash; <span class="dc-title">Removes duplicate values from an array</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.array-unique-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">function</span> <span class="methodname"><strong>array_unique</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$array</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = <strong><code><a href="array.constants.php#constant.sort-string">SORT_STRING</a></code></strong></span></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="para rdfs-comment">
   Takes an input <code class="parameter">array</code> and returns a new array
   without duplicate values.
  </p>
  <p class="para">
   Note that keys are preserved. If multiple elements compare equal under
   the given <code class="parameter">flags</code>, then the key and value of
   the first equal element will be retained.
  </p>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <p class="simpara">
    Two elements are considered equal if and only if
    <code class="literal">(string) $elem1 === (string) $elem2</code>, i.e.
    when the string representation is the same, the first element will be used.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.array-unique-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">array</code></dt>
     <dd>
      <p class="para">
       The input array.
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       The optional second parameter <code class="parameter">flags</code>
       may be used to modify the comparison behavior using these values:
      </p>
      <p class="para">
       Comparison type flags:
       <ul class="itemizedlist">
        <li class="listitem">
          <p class="simpara"><strong><code><a href="array.constants.php#constant.sort-regular">SORT_REGULAR</a></code></strong> - compare items normally
         (don&#039;t change types)</p>
         <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
          <p class="simpara">
           When combining <strong><code><a href="array.constants.php#constant.sort-regular">SORT_REGULAR</a></code></strong> with arrays
           mixing numeric and non-numeric strings, the sort-then-compare
           algorithm may not place equal elements adjacent, which can
           leave duplicates in the result. Use
           <strong><code><a href="array.constants.php#constant.sort-string">SORT_STRING</a></code></strong> to avoid this.
          </p>
         </p></blockquote>
        </li>
        <li class="listitem">
         <p class="simpara"><strong><code><a href="array.constants.php#constant.sort-numeric">SORT_NUMERIC</a></code></strong> - compare items numerically</p>
        </li>
        <li class="listitem">
         <p class="simpara"><strong><code><a href="array.constants.php#constant.sort-string">SORT_STRING</a></code></strong> - compare items as strings</p>
        </li>
        <li class="listitem">
         <p class="simpara"><strong><code><a href="array.constants.php#constant.sort-locale-string">SORT_LOCALE_STRING</a></code></strong> - compare items as
          strings, based on the current locale.
         </p>
        </li>
       </ul>
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.array-unique-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns the filtered array.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.array-unique-changelog">
  <h3 class="title">Журнал змін</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Версія</th>
       <th>Опис</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.2.0</td>
       <td>
        If <code class="parameter">flags</code> is <strong><code><a href="array.constants.php#constant.sort-string">SORT_STRING</a></code></strong>,
        the returned array is built by adding the unique elements to a new
        array; formerly, it was a copy of <code class="parameter">array</code> from
        which the non-unique elements were removed.
        Both hold the same elements under the same keys, but if the element
        with the largest integer key is among those removed, the index
        generated for an element appended to the returned array differs from
        the one <code class="parameter">array</code> would have generated.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.array-unique-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 <span class="function"><strong>array_unique()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php

$input </span><span style="color: #007700">= [</span><span style="color: #DD0000">"a" </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"green"</span><span style="color: #007700">, </span><span style="color: #DD0000">"red"</span><span style="color: #007700">, </span><span style="color: #DD0000">"b" </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"green"</span><span style="color: #007700">, </span><span style="color: #DD0000">"blue"</span><span style="color: #007700">, </span><span style="color: #DD0000">"red"</span><span style="color: #007700">];
</span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">array_unique</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">);
</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);

</span><span style="color: #0000BB">?&gt;</span></code></pre></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Array
(
    [a] =&gt; green
    [0] =&gt; red
    [1] =&gt; blue
)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Приклад #2 <span class="function"><strong>array_unique()</strong></span> and types</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php

$input </span><span style="color: #007700">= [</span><span style="color: #0000BB">4</span><span style="color: #007700">, </span><span style="color: #DD0000">"4"</span><span style="color: #007700">, </span><span style="color: #DD0000">"3"</span><span style="color: #007700">, </span><span style="color: #0000BB">4</span><span style="color: #007700">, </span><span style="color: #0000BB">3</span><span style="color: #007700">, </span><span style="color: #DD0000">"3"</span><span style="color: #007700">];
</span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">array_unique</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">);
</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);

</span><span style="color: #0000BB">?&gt;</span></code></pre></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">array(2) {
  [0]=&gt;
  int(4)
  [2]=&gt;
  string(1) &quot;3&quot;
}</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.array-unique-notes">
  <h3 class="title">Примітки</h3>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <p class="simpara">
    Note that <span class="function"><strong>array_unique()</strong></span> is not intended to
    work on multi dimensional arrays.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.array-unique-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.array-count-values.php" class="function" rel="rdfs-seeAlso">array_count_values()</a> - Counts the occurrences of each distinct value in an array</span></li>
   </ul>
  </p>
 </div>


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