Bifalgorithm post · Computer science one · Non-Contiguous Indices

How can key-value pairs be initialized in a PHP array?

How can key-value pairs be initialized in a PHP array? (Computer science one · Non-Contiguous Indices) — "Since associative arrays in PHP can be indexed by eit…

Ideas in this flowchart

  • PHP associative arrays support key-value initialization.
  • Associative arrays can use integer or string keys.
  • Their keys do not need to be ordered or contiguous.
  • Special initialization syntax defines both keys and values.
  • The double arrow (=>) denotes the mapping between a key and its value.
  • Example initialization: $arr = array(...).
  • The string key "foo" maps to the value 5.
  • The integer key 4 maps to the string value "bar".
  • The integer key 0 maps to the value 3.14.
Feed/

How can key-value pairs be initialized in a PHP array?

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\n549"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.