<?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 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.array-replace.php',
    1 => 'array_replace',
    2 => 'Remplace les &eacute;l&eacute;ments d\'un tableau par ceux d\'autres tableaux',
  ),
  'up' => 
  array (
    0 => 'ref.array.php',
    1 => 'Fonctions sur les tableaux',
  ),
  'prev' => 
  array (
    0 => 'function.array-reduce.php',
    1 => 'array_reduce',
  ),
  'next' => 
  array (
    0 => 'function.array-replace-recursive.php',
    1 => 'array_replace_recursive',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/array/functions/array-replace.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.array-replace" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">array_replace</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">array_replace</span> &mdash; <span class="dc-title">Remplace les éléments d&#039;un tableau par ceux d&#039;autres tableaux</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.array-replace-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>array_replace</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.array.php" class="type array">array</a></span> <code class="parameter">...$replacements</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_replace()</strong></span> crée un nouveau tableau et y assigne des
   éléments pour chaque clé dans chacun des tableaux fournis. Si une clé
   apparaît dans plusieurs tableaux d&#039;entrée, la valeur du tableau d&#039;entrée
   le plus à droite sera utilisée.
  </p>
  <p class="para">
   <span class="function"><strong>array_replace()</strong></span> ne traite pas les éléments de manière
   récursive, il remplace la valeur entière pour chaque clé lorsqu&#039;il effectue
   un remplacement.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.array-replace-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">array</code></dt>
     <dd>
      <p class="para">
       Le tableau dans lequel les éléments sont remplacés.
      </p>
     </dd>
    
    
     <dt><code class="parameter">replacements</code></dt>
     <dd>
      <p class="para">
       Tableaux depuis lesquels les éléments seront 
       extraits. Les valeurs des futurs tableaux
       écraseront les valeurs précédentes.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.array-replace-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne un <a href="language.types.array.php" class="link">tableau</a>.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.array-replace-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple avec <span class="function"><strong>array_replace()</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 />$base </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"orange"</span><span style="color: #007700">, </span><span style="color: #DD0000">"banana"</span><span style="color: #007700">, </span><span style="color: #DD0000">"apple"</span><span style="color: #007700">, </span><span style="color: #DD0000">"raspberry"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$replacements </span><span style="color: #007700">= array(</span><span style="color: #0000BB">0 </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"pineapple"</span><span style="color: #007700">, </span><span style="color: #0000BB">4 </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"cherry"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$replacements2 </span><span style="color: #007700">= array(</span><span style="color: #0000BB">0 </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"grape"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$basket </span><span style="color: #007700">= </span><span style="color: #0000BB">array_replace</span><span style="color: #007700">(</span><span style="color: #0000BB">$base</span><span style="color: #007700">, </span><span style="color: #0000BB">$replacements</span><span style="color: #007700">, </span><span style="color: #0000BB">$replacements2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$basket</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">array(5) {
  [0]=&gt;
  string(5) &quot;grape&quot;
  [1]=&gt;
  string(6) &quot;banana&quot;
  [2]=&gt;
  string(5) &quot;apple&quot;
  [3]=&gt;
  string(9) &quot;raspberry&quot;
  [4]=&gt;
  string(6) &quot;cherry&quot;
}</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-2">
    <p><strong>Exemple #2 Exemple de gestion des tableaux imbriqués</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$base </span><span style="color: #007700">= [ </span><span style="color: #DD0000">'citrus' </span><span style="color: #007700">=&gt; [ </span><span style="color: #DD0000">'orange'</span><span style="color: #007700">, </span><span style="color: #DD0000">'lemon' </span><span style="color: #007700">], </span><span style="color: #DD0000">'pome' </span><span style="color: #007700">=&gt; [ </span><span style="color: #DD0000">'apple' </span><span style="color: #007700">] ];<br /></span><span style="color: #0000BB">$replacements </span><span style="color: #007700">= [ </span><span style="color: #DD0000">'citrus' </span><span style="color: #007700">=&gt; [ </span><span style="color: #DD0000">'grapefruit' </span><span style="color: #007700">] ];<br /></span><span style="color: #0000BB">$replacements2 </span><span style="color: #007700">= [ </span><span style="color: #DD0000">'citrus' </span><span style="color: #007700">=&gt; [ </span><span style="color: #DD0000">'kumquat'</span><span style="color: #007700">, </span><span style="color: #DD0000">'citron' </span><span style="color: #007700">], </span><span style="color: #DD0000">'pome' </span><span style="color: #007700">=&gt; [ </span><span style="color: #DD0000">'loquat' </span><span style="color: #007700">] ];<br /><br /></span><span style="color: #0000BB">$basket </span><span style="color: #007700">= </span><span style="color: #0000BB">array_replace</span><span style="color: #007700">(</span><span style="color: #0000BB">$base</span><span style="color: #007700">, </span><span style="color: #0000BB">$replacements</span><span style="color: #007700">, </span><span style="color: #0000BB">$replacements2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$basket</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">array(2) {
  [&quot;citrus&quot;]=&gt;
  array(2) {
    [0]=&gt;
    string(7) &quot;kumquat&quot;
    [1]=&gt;
    string(6) &quot;citron&quot;
  }
  [&quot;pome&quot;]=&gt;
  array(1) {
    [0]=&gt;
    string(6) &quot;loquat&quot;
  }
}</pre>
</div>
    </div>
   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.array-replace-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.array-replace-recursive.php" class="function" rel="rdfs-seeAlso">array_replace_recursive()</a> - Remplace r&eacute;cursivement dans le premier tableau les &eacute;l&eacute;ments des autres tableaux fournis</span></li>
    <li><span class="function"><a href="function.array-merge.php" class="function" rel="rdfs-seeAlso">array_merge()</a> - Fusionne plusieurs tableaux en un seul</span></li>
   </ul>
  </p>
 </div>

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