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

  1. <?php
  2. $fa = SplFixedArray::fromArray(array(1 => 1, 0 => 2, 3 => 3));
  3.  
  4. var_dump($fa);
  5.  
  6. $fa = SplFixedArray::fromArray(array(1 => 1, 0 => 2, 3 => 3), false);
  7.  
  8. var_dump($fa);
  9. ?>

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

LoadingChargement en cours