<!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>Import a PHP array in a SplFixedArray instance</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="splfixedarray.current.html">SplFixedArray::current</a></div> <div class="next" style="text-align: right; float: right;"><a href="splfixedarray.getsize.html">SplFixedArray::getSize</a></div> <div class="up"><a href="class.splfixedarray.html">SplFixedArray</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="splfixedarray.fromarray" class="refentry"> <div class="refnamediv"> <h1 class="refname">SplFixedArray::fromArray</h1> <p class="verinfo">(PHP 5 >= 5.3.0)</p><p class="refpurpose"><span class="refname">SplFixedArray::fromArray</span> — <span class="dc-title">Import a PHP array in a <a href="class.splfixedarray.html" class="classname">SplFixedArray</a> instance</span></p> </div> <div class="refsect1 description" id="refsect1-splfixedarray.fromarray-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="modifier">static</span> <span class="type"><a href="class.splfixedarray.html" class="type SplFixedArray">SplFixedArray</a></span> <span class="methodname"><strong>SplFixedArray::fromArray</strong></span> ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$array</code></span> [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$save_indexes</code><span class="initializer"> = true</span></span> ] )</div> <p class="para rdfs-comment"> Import the PHP array <em><code class="parameter">array</code></em> in a new <a href="class.splfixedarray.html" class="classname">SplFixedArray</a> instance </p> </div> <div class="refsect1 parameters" id="refsect1-splfixedarray.fromarray-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">array</code></em></span> <dd> <p class="para"> The array to import. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">save_indexes</code></em></span> <dd> <p class="para"> Try to save the numeric indexes used in the original array. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-splfixedarray.fromarray-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns an instance of <a href="class.splfixedarray.html" class="classname">SplFixedArray</a> containing the array content. </p> </div> <div class="refsect1 examples" id="refsect1-splfixedarray.fromarray-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-3803"> <p><strong>Example #1 <span class="function"><strong>SplFixedArray::fromArray()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$fa </span><span style="color: #007700">= </span><span style="color: #0000BB">SplFixedArray</span><span style="color: #007700">::</span><span style="color: #0000BB">fromArray</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">0 </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">3</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$fa</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$fa </span><span style="color: #007700">= </span><span style="color: #0000BB">SplFixedArray</span><span style="color: #007700">::</span><span style="color: #0000BB">fromArray</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">0 </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">3</span><span style="color: #007700">), </span><span style="color: #0000BB">false</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$fa</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></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> object(SplFixedArray)#1 (4) { [0]=> int(2) [1]=> int(1) [2]=> NULL [3]=> int(3) } object(SplFixedArray)#2 (3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } </pre></div> </div> </div> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="splfixedarray.current.html">SplFixedArray::current</a></div> <div class="next" style="text-align: right; float: right;"><a href="splfixedarray.getsize.html">SplFixedArray::getSize</a></div> <div class="up"><a href="class.splfixedarray.html">SplFixedArray</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>