Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 2581

php-manual-en-7.2.11-1.mga7.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Fill an array with values</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-fill-keys.html">array_fill_keys</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-filter.html">array_filter</a></div>
 <div class="up"><a href="ref.array.html">Array Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><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)</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="type">array</span> <span class="methodname"><strong>array_fill</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$start_index</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$num</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>
   )</div>

  <p class="para rdfs-comment">
   Fills an array with
   <code class="parameter">num</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 
       (see <a href="function.array-fill.html#function.array-fill.example.basic" class="link">example</a>).
      </p>
     </dd>

    

    
     <dt>
<code class="parameter">num</code></dt>

     <dd>

      <p class="para">
       Number of elements to insert.
       Must be greater than or equal to zero.
      </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 <strong><code>E_WARNING</code></strong> if <code class="parameter">num</code> is
   less than zero.
  </p>
 </div>


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

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.6.0</td>
       <td>
        <code class="parameter">num</code> may now be zero. Previously,
        <code class="parameter">num</code> was required to be greater than zero.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </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-change-key-case.example-1">
    <p><strong>Example #1 <span class="function"><strong>array_fill()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$a&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_fill</span><span style="color: #007700">(</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">6</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'banana'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$b&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_fill</span><span style="color: #007700">(-</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">,&nbsp;</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">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$b</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="cdata"><pre>
Array
(
    [5]  =&gt; banana
    [6]  =&gt; banana
    [7]  =&gt; banana
    [8]  =&gt; banana
    [9]  =&gt; banana
    [10] =&gt; banana
)
Array
(
    [-2] =&gt; pear
    [0] =&gt; pear
    [1] =&gt; pear
    [2] =&gt; pear
)
</pre></div>
    </div>
   </div>
  </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.html" 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 class="member"><span class="function"><a href="function.array-fill-keys.html" class="function" rel="rdfs-seeAlso">array_fill_keys()</a> - Fill an array with values, specifying keys</span></li>
    <li class="member"><span class="function"><a href="function.str-repeat.html" class="function" rel="rdfs-seeAlso">str_repeat()</a> - Repeat a string</span></li>
    <li class="member"><span class="function"><a href="function.range.html" class="function" rel="rdfs-seeAlso">range()</a> - Create an array containing a range of elements</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-fill-keys.html">array_fill_keys</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-filter.html">array_filter</a></div>
 <div class="up"><a href="ref.array.html">Array Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>