(PHP 5 >= 5.3.0)
SplFixedArray::fromArray — Import a PHP array in a SplFixedArray instance
Import the PHP array array in a new SplFixedArray instance
The array to import.
Try to save the numeric indexes used in the original array.
Returns an instance of SplFixedArray containing the array content.
Beispiel #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);
?>
Das oben gezeigte Beispiel erzeugt folgende Ausgabe:
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) }
Memory footprint tests :
<?php
echo memory_get_usage()."\n"; // display 627760
$array = array_fill( 0, 2048, 'a' );
echo memory_get_usage()."\n"; // 824744, so 196984 for $array
unset( $array );
echo memory_get_usage()."\n"; // 627792
$spl=SplFixedArray::fromArray( array_fill( 0, 2048, 'a' ) );
echo memory_get_usage()."\n"; //644944, so just 17151 for $spl !!!
?>