Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<SplFixedArray::currentSplFixedArray::getIterator>
^SplFixedArrayLast updated: Mon, 26 Oct 2026

SplFixedArray::fromArray

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

SplFixedArray::fromArray — Import a PHP array in a SplFixedArray instance

Description

public static function SplFixedArray::fromArray(array $array, bool $preserveKeys = true): SplFixedArray

Import the PHP array array in a new SplFixedArray instance

Parameters

array

The array to import.

preserveKeys

Try to save the numeric indexes used in the original array.

Return Values

Returns an instance of SplFixedArray containing the array content.

Examples

Example #1 SplFixedArray::fromArray() example

<?php
$fa = SplFixedArray::fromArray(array(1 => 1, 0 => 2, 3 => 3));

var_dump($fa);

$fa = SplFixedArray::fromArray(array(1 => 1, 0 => 2, 3 => 3), false);

var_dump($fa);
?>

The above example will output:

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)
}


<SplFixedArray::currentSplFixedArray::getIterator>
^SplFixedArrayLast updated: Mon, 26 Oct 2026