Tableau en php

$champions = array( "zizou", "sampras", "nash" );
$monChampion = $champions[0];      → $monChampion contient "zizou"
$unAutre = $authors[1]; → $unAutre contient "sampras"
$pos = 1;
echo $champions[$pos + 1]; → Affiche "nash"
$champions[2] = "senna"; → Modif du tableau
$champions[] = "noah";→ Ajout en fin de tableau


$canards = array();
$canards[] = "riri";
$canards[] = "fifi";
$canards[] = "loulou";

$tableauAssociatif = array( "titre" ⇒ "PHP pour les nuls",
                   "auteur" ⇒ "Une burne",
                   "anneeDePublication" ⇒ 2001 );
                   
$monTitre = $tableauAssociatif ["titre"];    → $monTitre contient "PHP pour les nuls"                   
$tableauAssociatif["auteur"] = "Un pro"; → modif du tableau

print_r( $canards );

$chaineCanard = print_r( $canards, true );
echo $chaineCanard;  

echo count( $canards )."<br/>";

current($canards);
key($canards);
prev($canards);
next($canards);
end($canards);
reset($canards);


 foreach ( $canards as $value ) 
 {
     (do something with $value here)
 }
 foreach ( $array as $key ⇒ $value ) 
 {
     (do something with $key and/or $value here
 }
$mesBouquins = array(
    array(
      "titre" ⇒ "titre 1",
      "auteur" ⇒ "auteur 1",
      "anneeDePublication" ⇒ 1971
    ),
    array(
      "titre" ⇒ "titre 2",
      "auteur" ⇒ "auteur 2",
      "anneeDePublication" ⇒ 1972
    ),
    array(
      "titre" ⇒ "titre 3",
      "auteur" ⇒ "auteur 3",
      "anneeDePublication" ⇒ 2001
    ),
    array(
      "titre" ⇒ "titre 4",
      "auteur" ⇒ "Auteur 4",
      "anneeDePublication" ⇒ 2007
    ),
  );
  
  
  print_r( $mesBouquins[1] );

  echo "<br/>" . $mesBouquins[1]["titre"] . "<br/>";


  $Num = 0;

  foreach ( $mesBouquins as $bouquin ) 
  {

    $Num++;
    echo "<h2>Bouquin #$Num:</h2>";
    echo "<dl>";

    foreach ( $bouquin as $key ⇒ $value ) 
    {
      echo "<dt>$key</dt><dd>$value</dd>";
    }

    echo "</dl>";
  }

sort() and rsort() — For sorting indexed arrays

asort() and arsort() — For sorting associative arrays

ksort() and krsort() — For sorting associative arrays by key rather than by value

array_multisort() — A powerful function that can sort multiple arrays at once, or multidimensional arrays


Convertir en entier en chaine:
strval() –> num 2 str

Convertir une chaine en entier:
intval() –> str 2 num

Tri de tableau:
sort() et rsort() — Pour trier des tableaux indexes (r pour reverse )

asort() et arsort() — Pour trier des tableaux associatifs par la valeur

ksort() rt krsort() — Pour trier des tableaux associatifs par la clef

array_multisort() — Pour trier plusieurs tableaux par l'ordre du 1er tableau


array_unshift() — Adds one or more new elements to the start of an array

array_shift() — Removes the first element from the start of an array

array_push() — Adds one or more new elements to the end of an array

array_pop() — Removes the last element from the end of an array

array_splice() — Removes element(s) from and/or adds element(s) to any point in an array