<?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-flip.php',
    1 => 'array_flip',
    2 => 'Reemplaza las claves por los valores, y los valores por las claves',
  ),
  'up' => 
  array (
    0 => 'ref.array.php',
    1 => 'Funciones de Arrays',
  ),
  'prev' => 
  array (
    0 => 'function.array-first.php',
    1 => 'array_first',
  ),
  'next' => 
  array (
    0 => 'function.array-intersect.php',
    1 => 'array_intersect',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'es',
    'path' => 'reference/array/functions/array-flip.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.array-flip" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">array_flip</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">array_flip</span> &mdash; <span class="dc-title">Reemplaza las claves por los valores, y los valores por las claves</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.array-flip-description">
  <h3 class="title">Descripción</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>array_flip</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="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>array_flip()</strong></span> devuelve un <span class="type"><a href="language.types.array.php" class="type array">array</a></span> invertido,
   es decir, las claves de <code class="parameter">array</code> se convierten en valores y los valores de
   <code class="parameter">array</code> se convierten en claves.
  </p>
  <p class="para">
   Téngase en cuenta que los valores de <code class="parameter">array</code> deben
   ser claves válidas, es decir, deben ser <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> o
   <span class="type"><a href="language.types.string.php" class="type string">string</a></span>. Se emitirá una alerta si un valor es de un tipo que
   no es adecuado y la pareja en cuestión <em>no será incluida en el resultado</em>.
  </p>
  <p class="para">
   Si un valor no es único, solo la última clave será
   utilizada como valor, y todas las demás se perderán.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.array-flip-parameters">
  <h3 class="title">Parámetros</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">array</code></dt>
     <dd>
      <p class="para">
       Un array de pares clave/valor a invertir.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.array-flip-returnvalues">
  <h3 class="title">Valores devueltos</h3>
  <p class="para">
   Devuelve un array invertido.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.array-flip-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_flip()</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 />$input </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"oranges"</span><span style="color: #007700">, </span><span style="color: #DD0000">"apples"</span><span style="color: #007700">, </span><span style="color: #DD0000">"pears"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$flipped </span><span style="color: #007700">= </span><span style="color: #0000BB">array_flip</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$flipped</span><span style="color: #007700">);<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
(
    [oranges] =&gt; 0
    [apples] =&gt; 1
    [pears] =&gt; 2
)</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_flip()</strong></span> : colisión</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$input </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"a" </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #DD0000">"b" </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #DD0000">"c" </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$flipped </span><span style="color: #007700">= </span><span style="color: #0000BB">array_flip</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$flipped</span><span style="color: #007700">);<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
(
    [1] =&gt; b
    [2] =&gt; c
)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.array-flip-seealso">
  <h3 class="title">Ver también</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.array-values.php" class="function" rel="rdfs-seeAlso">array_values()</a> - Devuelve todos los valores de un array</span></li>
    <li><span class="function"><a href="function.array-keys.php" class="function" rel="rdfs-seeAlso">array_keys()</a> - Devuelve todas las claves o un conjunto de las claves de un array</span></li>
    <li><span class="function"><a href="function.array-reverse.php" class="function" rel="rdfs-seeAlso">array_reverse()</a> - Invierte el orden de los elementos de un array</span></li>
   </ul>
  </p>
 </div>

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