Bifalgorithm post · Computer science one · Key-Value Initialization

How does key-value initialization define PHP array keys and values?

How does key-value initialization define PHP array keys and values? (Computer science one · Key-Value Initialization) — "Since associative arrays in PHP can be…

Ideas in this flowchart

  • Initialisation des tableaux associatifs en PHP
  • Les tableaux associatifs peuvent utiliser des clés entières ou textuelles.
  • Les clés n’ont pas besoin d’être ordonnées ou contiguës.
  • Une syntaxe spéciale permet de définir les clés et les valeurs lors de l’initialisation.
  • La double flèche => indique la correspondance entre une clé et une valeur.
  • $arr = array(...)
  • La clé "foo" correspond à la valeur 5.
  • La clé 4 correspond à la valeur "bar".
  • La clé 0 correspond à la valeur 3.14.
Feed/

How does key-value initialization define PHP array keys and values?

No cover

Channel

Computer science one

1 page

"Since associative arrays in PHP can be indexed by either integers or strings and need not be ordered or contiguous, we can use a special key-value initialization syntax to define not only the values, but the keys that map to those values when we initialize an array. The “double arrow,” => is used to denote the mapping.\n\n1 $arr = array(\n\n2 \"foo\" => 5,\n\n3 4 => \"bar\",\n\n4 0 => 3.14,\n\n5"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.