<?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 => 'es',
  ),
  'this' => 
  array (
    0 => 'function.array-unique.php',
    1 => 'array_unique',
    2 => 'Elimina los valores duplicados de un array',
  ),
  'up' => 
  array (
    0 => 'ref.array.php',
    1 => 'Funciones de Arrays',
  ),
  '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' => 'es',
    '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">Elimina los valores duplicados de un array</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.array-unique-description">
  <h3 class="title">Descripción</h3>
  <div class="methodsynopsis dc-description">
   <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">
   <span class="function"><strong>array_unique()</strong></span> extrae del array
   <code class="parameter">array</code> los valores distintos,
   y elimina todos los duplicados.
  </p>
  <p class="para">
   Tenga en cuenta que las claves se preservan. Si varios elementos comparados
   son iguales bajo el <code class="parameter">flags</code> dado, entonces la clave
   y el valor del primer elemento igual serán conservados.
  </p>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <span class="simpara">
    Dos elementos se consideran iguales si y solo si
    <code class="literal">(string) $elem1 === (string) $elem2</code>, es decir,
    cuando la representación en string es idéntica.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.array-unique-parameters">
  <h3 class="title">Parámetros</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">array</code></dt>
     <dd>
      <p class="para">
       El array de entrada.
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       El segundo parámetro opcional <code class="parameter">flags</code>
       puede ser utilizado para modificar el comportamiento de comparación
       utilizando los siguientes valores:
      </p>
      <p class="para">
       Flag de tipo de comparación:
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara"><strong><code><a href="array.constants.php#constant.sort-regular">SORT_REGULAR</a></code></strong> - compara los elementos normalmente
         (no modifica los tipos)</span>
        </li>
        <li class="listitem">
         <span class="simpara"><strong><code><a href="array.constants.php#constant.sort-numeric">SORT_NUMERIC</a></code></strong> - compara los elementos
         numéricamente</span>
        </li>
        <li class="listitem">
         <span class="simpara"><strong><code><a href="array.constants.php#constant.sort-string">SORT_STRING</a></code></strong> - compara los elementos como strings</span>
        </li>
        <li class="listitem">
         <span class="simpara"><strong><code><a href="array.constants.php#constant.sort-locale-string">SORT_LOCALE_STRING</a></code></strong> - compara los elementos como
         strings, según la configuración local actual.
         </span>
        </li>
       </ul>
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.array-unique-returnvalues">
  <h3 class="title">Valores devueltos</h3>
  <p class="para">
   Devuelve el array filtrado.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.array-unique-changelog">
  <h3 class="title">Historial de cambios</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Versión</th>
       <th>Descripción</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.2.0</td>
       <td>
        Si <code class="parameter">flags</code> es <strong><code><a href="array.constants.php#constant.sort-string">SORT_STRING</a></code></strong>,
        anteriormente <code class="parameter">array</code> era copiado y los elementos
        no únicos eran eliminados (sin comprimir el array después), pero
        ahora se construye un nuevo array añadiendo los elementos únicos.
        Como consecuencia, el resultado final puede tener índices numéricos diferentes.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.array-unique-examples">
  <h3 class="title">Ejemplos</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Ejemplo #1 Ejemplo con <span class="function"><strong>array_unique()</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 /><br />$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">];<br /></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">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>El ejemplo anterior mostrará:</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>Ejemplo #2 Ejemplo con <span class="function"><strong>array_unique()</strong></span> y los tipos</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$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">];<br /></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">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>El ejemplo anterior mostrará:</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">Notas</h3>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <span class="simpara">
    Tenga en cuenta que <span class="function"><strong>array_unique()</strong></span> no funciona
    con arrays multidimensionales.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.array-unique-seealso">
  <h3 class="title">Ver también</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> - Cuenta las ocurrencias de cada valor distinto en un array</span></li>
   </ul>
  </p>
 </div>


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