Bifalgorithm post · Computer science one · Strings as Indices

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 · Strings as Indices) — "Since associative arrays in PHP can be index…

Ideas in this flowchart

  • PHP associative arrays support explicit key-value initialization.
  • Keys can be integers or strings.
  • Keys need not be ordered or contiguous.
  • Special initialization syntax defines both keys and values.
  • The double arrow (=>) denotes the mapping between a key and its value.
  • $arr = array("foo" => 5, 4 => "bar", 0 => 3.14);
  • "foo" maps to 5.
  • 4 maps to "bar".
  • 0 maps to 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\n549"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.