<?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.php',
    1 => 'array',
    2 => 'Create an array',
  ),
  'up' => 
  array (
    0 => 'ref.array.php',
    1 => 'Функції для роботи з масивами',
  ),
  'prev' => 
  array (
    0 => 'ref.array.php',
    1 => 'Функції для роботи з масивами',
  ),
  'next' => 
  array (
    0 => 'function.array-all.php',
    1 => 'array_all',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/array/functions/array.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.array" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">array</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">array</span> &mdash; <span class="dc-title">Create an array</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.array-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>array</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">...$values</code></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="para rdfs-comment">
   Creates an array. Read the section on the
   <a href="language.types.array.php" class="link">array type</a> for more information
   on what an array is, including details about the alternative bracket syntax (<code class="literal">[]</code>).
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.array-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">values</code></dt>
     <dd>
      <p class="para">
       Syntax &quot;index =&gt; values&quot;, separated by commas, define index
       and values. index may be of type string or integer. When index is
       omitted, an integer index is automatically generated, starting
       at 0. If index is an integer, next generated index will
       be the biggest integer index + 1. Note that when two identical
       indices are defined, the last overwrites the first.
      </p>
      <p class="para">
       Having a trailing comma after the last defined array entry, while
       unusual, is a valid syntax.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.array-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns an array of the parameters.  The parameters can be given
   an index with the <code class="literal">=&gt;</code> operator.  Read the section
   on the <a href="language.types.array.php" class="link">array type</a> for more
   information on what an array is.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.array-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   The following example demonstrates how to create a
   two-dimensional array, how to specify keys for associative
   arrays, and how to skip-and-continue numeric indices in normal
   arrays.
   <div class="example" id="example-1">
    <p><strong>Приклад #1 <span class="function"><strong>array()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$fruits </span><span style="color: #007700">= array (<br />    </span><span style="color: #DD0000">"fruits"  </span><span style="color: #007700">=&gt; array(</span><span style="color: #DD0000">"a" </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"orange"</span><span style="color: #007700">, </span><span style="color: #DD0000">"b" </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"banana"</span><span style="color: #007700">, </span><span style="color: #DD0000">"c" </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"apple"</span><span style="color: #007700">),<br />    </span><span style="color: #DD0000">"numbers" </span><span style="color: #007700">=&gt; array(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #0000BB">3</span><span style="color: #007700">, </span><span style="color: #0000BB">4</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">),<br />    </span><span style="color: #DD0000">"holes"   </span><span style="color: #007700">=&gt; array(</span><span style="color: #DD0000">"first"</span><span style="color: #007700">, </span><span style="color: #0000BB">5 </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"second"</span><span style="color: #007700">, </span><span style="color: #DD0000">"third"</span><span style="color: #007700">)<br />);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$fruits</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Приклад #2 Automatic index with <span class="function"><strong>array()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$array </span><span style="color: #007700">= array(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">,  </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">8 </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">4 </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">19</span><span style="color: #007700">, </span><span style="color: #0000BB">3 </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">13</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Array
(
    [0] =&gt; 1
    [1] =&gt; 1
    [2] =&gt; 1
    [3] =&gt; 13
    [4] =&gt; 1
    [8] =&gt; 1
    [9] =&gt; 19
)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   Note that index &#039;3&#039; is defined twice, and keep its final value of 13.
   Index 4 is defined after index 8, and next generated index (value 19)
   is 9, since biggest index was 8.
  </p>
  <p class="para">
   This example creates a 1-based array.
   <div class="example" id="example-3">
    <p><strong>Приклад #3 1-based index with <span class="function"><strong>array()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$firstQuarter </span><span style="color: #007700">= array(</span><span style="color: #0000BB">1 </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'January'</span><span style="color: #007700">, </span><span style="color: #DD0000">'February'</span><span style="color: #007700">, </span><span style="color: #DD0000">'March'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$firstQuarter</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Array
(
    [1] =&gt; January
    [2] =&gt; February
    [3] =&gt; March
)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   As in Perl, you can access a value from the array inside double quotes.
   However, with PHP you&#039;ll need to enclose your array between curly braces.
   <div class="example" id="example-4">
    <p><strong>Приклад #4 Accessing an array inside double quotes</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$foo </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'bar' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'baz'</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Hello </span><span style="color: #007700">{</span><span style="color: #0000BB">$foo</span><span style="color: #007700">[</span><span style="color: #DD0000">'bar'</span><span style="color: #007700">]}</span><span style="color: #DD0000">!"</span><span style="color: #007700">; </span><span style="color: #FF8000">// Hello baz!<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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

 <div class="refsect1 notes" id="refsect1-function.array-notes">
  <h3 class="title">Примітки</h3>
  <p class="para">
   <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
    <p class="para">
     <span class="function"><strong>array()</strong></span> is a language construct used to
     represent literal arrays, and not a regular function.
    </p>
   </p></blockquote>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.array-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.array-pad.php" class="function" rel="rdfs-seeAlso">array_pad()</a> - Pad array to the specified length with a value</span></li>
    <li><span class="function"><a href="function.list.php" class="function" rel="rdfs-seeAlso">list()</a> - Assign variables as if they were an array</span></li>
    <li><span class="function"><a href="function.count.php" class="function" rel="rdfs-seeAlso">count()</a> - Підраховує кількість елементів масиву або об&rsquo;єкту
   Countable</span></li>
    <li><span class="function"><a href="function.range.php" class="function" rel="rdfs-seeAlso">range()</a> - Створює масив, який містить послідовність елементів</span></li>
    <li><a href="control-structures.foreach.php" class="link">foreach</a></li>
    <li>The <a href="language.types.array.php" class="link">array</a> type</li>
   </ul>
  </p>
 </div>

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