downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

SplFixedArray::getSize> <SplFixedArray::current
[edit] Last updated: Fri, 25 May 2012

view this page in

SplFixedArray::fromArray

(PHP 5 >= 5.3.0)

SplFixedArray::fromArrayImporte un tableau PHP dans un tableau à taille fixe

Description

public static SplFixedArray SplFixedArray::fromArray ( array $array [, bool $save_indexes = true ] )

Importe le tableau PHP array dans un tableau à taille fixe.

Liste de paramètres

array

La tableau à importer.

save_indexes

Tente de préserver les index numérique du tableau original.

Valeurs de retour

Retourne un objet SplFixedArray avec le même contenu que le tableau passé en argument.

Exemples

Exemple #1 Exemple avec SplFixedArray::fromArray()

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

var_dump($fa);

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

var_dump($fa);
?>

L'exemple ci-dessus va afficher :

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



add a note add a note User Contributed Notes SplFixedArray::fromArray
MuLoT 10-Dec-2010 09:15
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 !!!
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites