<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/spl.datastructures.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'class.splfixedarray.php',
    1 => 'SplFixedArray',
    2 => 'The SplFixedArray class',
  ),
  'up' => 
  array (
    0 => 'spl.datastructures.php',
    1 => 'Datastructures',
  ),
  'prev' => 
  array (
    0 => 'splpriorityqueue.valid.php',
    1 => 'SplPriorityQueue::valid',
  ),
  'next' => 
  array (
    0 => 'splfixedarray.construct.php',
    1 => 'SplFixedArray::__construct',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/spl/splfixedarray.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/class.splfixedarray.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="class.splfixedarray" class="reference">
 <h1 class="title">The SplFixedArray class</h1>
 
 
 <div class="partintro"><p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8)</p>
 

  <div class="section" id="splfixedarray.intro">
   <h2 class="title">Einführung</h2>
   <p class="para">
    The SplFixedArray class provides the main functionalities of array. The 
    main difference between a SplFixedArray and a normal PHP array is that 
    the SplFixedArray must be resized manually and allows only integers within 
    the range as indexes. The advantage is that it uses less memory than
    a standard <span class="type"><a href="language.types.array.php" class="type array">array</a></span>.
   </p>
  </div>

 
  <div class="section" id="splfixedarray.synopsis">
   <h2 class="title">Klassenbeschreibung</h2>
 

   <div class="classsynopsis"><div class="classsynopsisinfo">
    
     <span class="modifier">class</span> <strong class="classname"><strong class="classname">SplFixedArray</strong></strong>
    

    
     <span class="modifier">implements</span>
      <a href="class.iteratoraggregate.php" class="interfacename">IteratorAggregate</a>,

     <a href="class.arrayaccess.php" class="interfacename">ArrayAccess</a>,

     <a href="class.countable.php" class="interfacename">Countable</a>,

     <a href="class.jsonserializable.php" class="interfacename">JsonSerializable</a> {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Methoden */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.construct.php" class="methodname">__construct</a></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$size</code><span class="initializer"> = 0</span></span>)</div>

    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.count.php" class="methodname">count</a></span>(): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.current.php" class="methodname">current</a></span>(): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="splfixedarray.fromarray.php" class="methodname">fromArray</a></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.boolean.php" class="type bool">bool</a></span> <code class="parameter">$preserveKeys</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong></span></span>): <span class="type"><a href="class.splfixedarray.php" class="type SplFixedArray">SplFixedArray</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.getiterator.php" class="methodname">getIterator</a></span>(): <span class="type"><a href="class.iterator.php" class="type Iterator">Iterator</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.getsize.php" class="methodname">getSize</a></span>(): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.jsonserialize.php" class="methodname">jsonSerialize</a></span>(): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.key.php" class="methodname">key</a></span>(): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.next.php" class="methodname">next</a></span>(): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.offsetexists.php" class="methodname">offsetExists</a></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$index</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.offsetget.php" class="methodname">offsetGet</a></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$index</code></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.offsetset.php" class="methodname">offsetSet</a></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$index</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.void.php" class="type void">void</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.offsetunset.php" class="methodname">offsetUnset</a></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$index</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.rewind.php" class="methodname">rewind</a></span>(): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.serialize.php" class="methodname">__serialize</a></span>(): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.setsize.php" class="methodname">setSize</a></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$size</code></span>): <span class="type"><a href="language.types.singleton.php" class="type true">true</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.toarray.php" class="methodname">toArray</a></span>(): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.unserialize.php" class="methodname">__unserialize</a></span>(<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$data</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.valid.php" class="methodname">valid</a></span>(): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>
<div class="methodsynopsis dc-description"><span class="attribute"><a href="class.deprecated.php">#[\Deprecated]</a> </span><br>
   <span class="modifier">public</span> <span class="methodname"><a href="splfixedarray.wakeup.php" class="methodname">__wakeup</a></span>(): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

   }</div>
 
  </div>

  <div class="section">
   <h2 class="title">Changelog</h2>
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Beschreibung</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.2.0</td>
       <td>
        The <span class="methodname"><a href="splfixedarray.serialize.php" class="methodname">SplFixedArray::__serialize()</a></span> and
        <span class="methodname"><a href="splfixedarray.unserialize.php" class="methodname">SplFixedArray::__unserialize()</a></span>
        magic methods have been added to <span class="classname"><strong class="classname">SplFixedArray</strong></span>.
       </td>
      </tr>

      <tr>
       <td>8.1.0</td>
       <td>
        <span class="classname"><strong class="classname">SplFixedArray</strong></span> implements
        <span class="interfacename"><a href="class.jsonserializable.php" class="interfacename">JsonSerializable</a></span> now.
       </td>
      </tr>

      <tr>
       <td>8.0.0</td>
       <td>
        <span class="classname"><strong class="classname">SplFixedArray</strong></span> implements
        <span class="interfacename"><a href="class.iteratoraggregate.php" class="interfacename">IteratorAggregate</a></span> now.
        Previously, <span class="interfacename"><a href="class.iterator.php" class="interfacename">Iterator</a></span> was implemented instead.
       </td>
      </tr>

     </tbody>
    
   </table>

  </div>


  <div class="section" id="splfixedarray.examples">
   <h2 class="title">Beispiele</h2>
   <p class="para">
    <div class="example" id="example-1">
     <p><strong>Beispiel #1 <span class="classname"><strong class="classname">SplFixedArray</strong></span> usage example</strong></p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Initialize the array with a fixed length<br /></span><span style="color: #0000BB">$array </span><span style="color: #007700">= new </span><span style="color: #0000BB">SplFixedArray</span><span style="color: #007700">(</span><span style="color: #0000BB">5</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$array</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">] = </span><span style="color: #0000BB">2</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$array</span><span style="color: #007700">[</span><span style="color: #0000BB">4</span><span style="color: #007700">] = </span><span style="color: #DD0000">"foo"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]); </span><span style="color: #FF8000">// NULL<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]); </span><span style="color: #FF8000">// int(2)<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">[</span><span style="color: #DD0000">"4"</span><span style="color: #007700">]); </span><span style="color: #FF8000">// string(3) "foo"<br /><br />// Increase the size of the array to 10<br /></span><span style="color: #0000BB">$array</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setSize</span><span style="color: #007700">(</span><span style="color: #0000BB">10</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$array</span><span style="color: #007700">[</span><span style="color: #0000BB">9</span><span style="color: #007700">] = </span><span style="color: #DD0000">"asdf"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Shrink the array to a size of 2<br /></span><span style="color: #0000BB">$array</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setSize</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// The following lines throw a RuntimeException: Index invalid or out of range<br /></span><span style="color: #007700">try {<br />    </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">[</span><span style="color: #DD0000">"non-numeric"</span><span style="color: #007700">]);<br />} catch(</span><span style="color: #0000BB">RuntimeException $re</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"RuntimeException: "</span><span style="color: #007700">.</span><span style="color: #0000BB">$re</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">().</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br />try {<br />    </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">[-</span><span style="color: #0000BB">1</span><span style="color: #007700">]);<br />} catch(</span><span style="color: #0000BB">RuntimeException $re</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"RuntimeException: "</span><span style="color: #007700">.</span><span style="color: #0000BB">$re</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">().</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br />try {<br />    </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">[</span><span style="color: #0000BB">5</span><span style="color: #007700">]);<br />} catch(</span><span style="color: #0000BB">RuntimeException $re</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"RuntimeException: "</span><span style="color: #007700">.</span><span style="color: #0000BB">$re</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">().</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
NULL
int(2)
string(3) &quot;foo&quot;
RuntimeException: Index invalid or out of range
RuntimeException: Index invalid or out of range
RuntimeException: Index invalid or out of range
</pre></div>
     </div>
    </div>
   </p>
  </div>

 

 
 </div>
 
 






































































































 
<h2>Inhaltsverzeichnis</h2><ul class="chunklist chunklist_reference"><li><a href="splfixedarray.construct.php">SplFixedArray::__construct</a> — Constructs a new fixed array</li><li><a href="splfixedarray.count.php">SplFixedArray::count</a> — Returns the size of the array</li><li><a href="splfixedarray.current.php">SplFixedArray::current</a> — Return current array entry</li><li><a href="splfixedarray.fromarray.php">SplFixedArray::fromArray</a> — Import a PHP array in a SplFixedArray instance</li><li><a href="splfixedarray.getiterator.php">SplFixedArray::getIterator</a> — Retrieve the iterator to go through the array</li><li><a href="splfixedarray.getsize.php">SplFixedArray::getSize</a> — Gets the size of the array</li><li><a href="splfixedarray.jsonserialize.php">SplFixedArray::jsonSerialize</a> — Returns a representation that can be converted to JSON</li><li><a href="splfixedarray.key.php">SplFixedArray::key</a> — Return current array index</li><li><a href="splfixedarray.next.php">SplFixedArray::next</a> — Move to next entry</li><li><a href="splfixedarray.offsetexists.php">SplFixedArray::offsetExists</a> — Returns whether the requested index exists</li><li><a href="splfixedarray.offsetget.php">SplFixedArray::offsetGet</a> — Returns the value at the specified index</li><li><a href="splfixedarray.offsetset.php">SplFixedArray::offsetSet</a> — Sets a new value at a specified index</li><li><a href="splfixedarray.offsetunset.php">SplFixedArray::offsetUnset</a> — Unsets the value at the specified $index</li><li><a href="splfixedarray.rewind.php">SplFixedArray::rewind</a> — Rewind iterator back to the start</li><li><a href="splfixedarray.serialize.php">SplFixedArray::__serialize</a> — Serializes the SplFixedArray object</li><li><a href="splfixedarray.setsize.php">SplFixedArray::setSize</a> — Change the size of an array</li><li><a href="splfixedarray.toarray.php">SplFixedArray::toArray</a> — Returns a PHP array from the fixed array</li><li><a href="splfixedarray.unserialize.php">SplFixedArray::__unserialize</a> — Deserializes the data parameter into an SplFixedArray object</li><li><a href="splfixedarray.valid.php">SplFixedArray::valid</a> — Check whether the array contains more elements</li><li><a href="splfixedarray.wakeup.php">SplFixedArray::__wakeup</a> — Reinitialises the array after being unserialised</li></ul>
</div>
<?php manual_footer($setup); ?>