<?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-fill.php',
    1 => 'array_fill',
    2 => 'Remplit un tableau avec une m&ecirc;me valeur',
  ),
  'up' => 
  array (
    0 => 'ref.array.php',
    1 => 'Fonctions sur les tableaux',
  ),
  'prev' => 
  array (
    0 => 'function.array-diff-ukey.php',
    1 => 'array_diff_ukey',
  ),
  'next' => 
  array (
    0 => 'function.array-fill-keys.php',
    1 => 'array_fill_keys',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/array/functions/array-fill.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.array-fill" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">array_fill</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">array_fill</span> &mdash; <span class="dc-title">Remplit un tableau avec une même valeur</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.array-fill-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>array_fill</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$start_index</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$count</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="para rdfs-comment">
   Crée un tableau avec <code class="parameter">count</code> entrées, toutes de valeur
   <code class="parameter">value</code>. Les index commencent à la valeur
   <code class="parameter">start_index</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.array-fill-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>

    
     <dt><code class="parameter">start_index</code></dt>
     <dd>
      <p class="para">
       Le premier index du tableau retourné.
      </p>
      <p class="para">
       Si <code class="parameter">start_index</code> est négatif,
       le premier index du tableau retourné sera
       <code class="parameter">start_index</code>, suivi par des indices commençant à
       zéro dans les versions antérieures à PHP 8.0.0 ;
       à partir de PHP 8.0.0, les indices négatifs sont incrémentés normalement.
       (voir l&#039;<a href="function.array-fill.php#function.array-fill.example.negative-start-index" class="link">exemple</a>).
      </p>
     </dd>
    

    
     <dt><code class="parameter">count</code></dt>
     <dd>
      <p class="para">
       Nombre d&#039;éléments à insérer.
       Doit être supérieur ou égal à zéro, et inférieur ou égal à <code class="literal">2147483647</code>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       Valeur à utiliser pour remplir le tableau
      </p>
     </dd>
    

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


 <div class="refsect1 returnvalues" id="refsect1-function.array-fill-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne le tableau rempli.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.array-fill-errors">
  <h3 class="title">Erreurs / Exceptions</h3>
  <p class="para">
   Lance une exception <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> si
   <code class="parameter">count</code> est en dehors de la plage permise.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.array-fill-changelog">
  <h3 class="title">Historique</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       La fonction <span class="function"><strong>array_fill()</strong></span> lance désormais une <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span>
       si <code class="parameter">count</code> est en dehors de la plage permise ;
       auparavant une alerte de niveau <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> était émise, et la fonction retournait <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.array-fill-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="function.array-fill.example.basic">
    <p><strong>Exemple #1 Exemple avec <span class="function"><strong>array_fill()</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 />$a </span><span style="color: #007700">= </span><span style="color: #0000BB">array_fill</span><span style="color: #007700">(</span><span style="color: #0000BB">5</span><span style="color: #007700">, </span><span style="color: #0000BB">6</span><span style="color: #007700">, </span><span style="color: #DD0000">'banana'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</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]  =&gt; banana
    [6]  =&gt; banana
    [7]  =&gt; banana
    [8]  =&gt; banana
    [9]  =&gt; banana
    [10] =&gt; banana
)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="function.array-fill.example.negative-start-index">
    <p><strong>Exemple #2 Exemple de <span class="function"><strong>array_fill()</strong></span> avec un indice de départ négatif</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$a </span><span style="color: #007700">= </span><span style="color: #0000BB">array_fill</span><span style="color: #007700">(-</span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #0000BB">4</span><span style="color: #007700">, </span><span style="color: #DD0000">'pear'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Résultat de l&#039;exemple ci-dessus en PHP 8 :</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Array
(
    [-2] =&gt; pear
    [-1] =&gt; pear
    [0] =&gt; pear
    [1] =&gt; pear
)</pre>
</div>
    </div>
    <div class="example-contents"><p>Résultat de l&#039;exemple ci-dessus en PHP 7 :</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Array
(
    [-2] =&gt; pear
    [0] =&gt; pear
    [1] =&gt; pear
    [2] =&gt; pear
)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   Il est à noter que l&#039;indice <code class="literal">-1</code> n&#039;est pas présent antérieurement à PHP 8.0.0.
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.array-fill-notes">
  <h3 class="title">Notes</h3>
  <p class="para">
   Voir aussi la section du manuel sur les
   <a href="language.types.array.php" class="link">tableaux</a>
   pour plus d&#039;informations sur les clés négatives.
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.array-fill-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.array-fill-keys.php" class="function" rel="rdfs-seeAlso">array_fill_keys()</a> - Remplit un tableau avec des valeurs, en sp&eacute;cifiant les cl&eacute;s</span></li>
    <li><span class="function"><a href="function.str-repeat.php" class="function" rel="rdfs-seeAlso">str_repeat()</a> - R&eacute;p&egrave;te une cha&icirc;ne</span></li>
    <li><span class="function"><a href="function.range.php" class="function" rel="rdfs-seeAlso">range()</a> - Cr&eacute;e un tableau contenant un intervalle d'&eacute;l&eacute;ments</span></li>
   </ul>
  </p>
 </div>


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