<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.array-fill.php',
    1 => 'array_fill',
    2 => 'Fill an array with values',
  ),
  'up' => 
  array (
    0 => 'ref.array.php',
    1 => 'Array Functions',
  ),
  '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' => 'en',
    '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">Fill an array with values</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">
   Fills an array with
   <code class="parameter">count</code> entries of the value of the
   <code class="parameter">value</code> parameter, keys starting at the
   <code class="parameter">start_index</code> parameter.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.array-fill-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    
     <dt><code class="parameter">start_index</code></dt>
     <dd>
      <p class="para">
       The first index of the returned array.
      </p>
      <p class="para">
       If <code class="parameter">start_index</code> is negative, 
       the first index of the returned array will be 
       <code class="parameter">start_index</code> and the following 
       indices will start from zero prior to PHP 8.0.0;
       as of PHP 8.0.0, negative keys are incremented normally
       (see <a href="function.array-fill.php#function.array-fill.example.negative-start-index" class="link">example</a>).
      </p>
     </dd>
    

    
     <dt><code class="parameter">count</code></dt>
     <dd>
      <p class="para">
       Number of elements to insert.
       Must be greater than or equal to zero, and less than or equal to <code class="literal">2147483647</code>.
      </p>
     </dd>
    

    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       Value to use for filling
      </p>
     </dd>
    

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


 <div class="refsect1 returnvalues" id="refsect1-function.array-fill-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the filled array
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.array-fill-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   Throws a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> if <code class="parameter">count</code> is
   out of range.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.array-fill-changelog">
  <h3 class="title">Changelog</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>
       <span class="function"><strong>array_fill()</strong></span> now throws a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span>
       if <code class="parameter">count</code> is out of range; previously <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>
       was raised, and the function returned <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">Examples</h3>
  <p class="para">
   <div class="example" id="function.array-fill.example.basic">
    <p><strong>Example #1 <span class="function"><strong>array_fill()</strong></span> example</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>The above example will output:</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>Example #2 <span class="function"><strong>array_fill()</strong></span> example with a negative start index</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>Output of the above example in 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>Output of the above example in 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">
   Note that index <code class="literal">-1</code> is not present prior to PHP 8.0.0.
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.array-fill-notes">
  <h3 class="title">Notes</h3>
  <p class="para">
   See also the <a href="language.types.array.php" class="link">Arrays</a> 
   section of manual for a detailed explanation of negative keys.
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.array-fill-seealso">
  <h3 class="title">See Also</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> - Fill an array with values, specifying keys</span></li>
    <li><span class="function"><a href="function.str-repeat.php" class="function" rel="rdfs-seeAlso">str_repeat()</a> - Repeat a string</span></li>
    <li><span class="function"><a href="function.range.php" class="function" rel="rdfs-seeAlso">range()</a> - Create an array containing a range of elements</span></li>
   </ul>
  </p>
 </div>


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