<?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 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.array-pad.php',
    1 => 'array_pad',
    2 => 'Pad array to the specified length with a value',
  ),
  'up' => 
  array (
    0 => 'ref.array.php',
    1 => 'Функції для роботи з масивами',
  ),
  'prev' => 
  array (
    0 => 'function.array-multisort.php',
    1 => 'array_multisort',
  ),
  'next' => 
  array (
    0 => 'function.array-pop.php',
    1 => 'array_pop',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/array/functions/array-pad.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.array-pad" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">array_pad</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">array_pad</span> &mdash; <span class="dc-title">Pad array to the specified length with a value</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.array-pad-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>array_pad</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.integer.php" class="type int">int</a></span> <code class="parameter">$length</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">
   <span class="function"><strong>array_pad()</strong></span> returns a copy of the
   <code class="parameter">array</code> padded to size specified by
   <code class="parameter">length</code> with value
   <code class="parameter">value</code>. If
   <code class="parameter">length</code> is positive then the array is
   padded on the right, if it&#039;s negative then on the left. If the
   absolute value of <code class="parameter">length</code> is less than or
   equal to the length of the <code class="parameter">array</code> then no
   padding takes place.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.array-pad-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">array</code></dt>
     <dd>
      <p class="para">
       Initial array of values to pad.
      </p>
     </dd>
    
    
     <dt><code class="parameter">length</code></dt>
     <dd>
      <p class="para">
       New size of the array.
      </p>
     </dd>
    
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       Value to pad if <code class="parameter">array</code> is less than
       <code class="parameter">length</code>.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.array-pad-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns a copy of the <code class="parameter">array</code> padded to size specified
   by <code class="parameter">length</code> with value 
   <code class="parameter">value</code>. If <code class="parameter">length</code> is 
   positive then the array is padded on the right, if it&#039;s negative then 
   on the left. If the absolute value of <code class="parameter">length</code> is less
   than or equal to the length of the <code class="parameter">array</code> then no
   padding takes place.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.array-pad-changelog">
  <h3 class="title">Журнал змін</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Версія</th>
       <th>Опис</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.3.0</td>
       <td>
        Prior to 8.3, only 1048576 elements could be added at once.
        Now it is limited only by the maximum size of an array instead.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.array-pad-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 <span class="function"><strong>array_pad()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$input </span><span style="color: #007700">= array(</span><span style="color: #0000BB">12</span><span style="color: #007700">, </span><span style="color: #0000BB">10</span><span style="color: #007700">, </span><span style="color: #0000BB">9</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">array_pad</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">, </span><span style="color: #0000BB">5</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// result is array(12, 10, 9, 0, 0)<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">join</span><span style="color: #007700">(</span><span style="color: #DD0000">', '</span><span style="color: #007700">, </span><span style="color: #0000BB">$result</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">array_pad</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">, -</span><span style="color: #0000BB">7</span><span style="color: #007700">, -</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// result is array(-1, -1, -1, -1, 12, 10, 9)<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">join</span><span style="color: #007700">(</span><span style="color: #DD0000">', '</span><span style="color: #007700">, </span><span style="color: #0000BB">$result</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">array_pad</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #DD0000">"noop"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// not padded<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">join</span><span style="color: #007700">(</span><span style="color: #DD0000">', '</span><span style="color: #007700">, </span><span style="color: #0000BB">$result</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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

 <div class="refsect1 seealso" id="refsect1-function.array-pad-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.array-fill.php" class="function" rel="rdfs-seeAlso">array_fill()</a> - Fill an array with values</span></li>
    <li><span class="function"><a href="function.range.php" class="function" rel="rdfs-seeAlso">range()</a> - Створює масив, який містить послідовність елементів</span></li>
   </ul>
  </p>
 </div>

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