Chapter

Strings as Indices

From ComputerScienceOne by Dr Chris Bourke

Concepts

  1. How can strings be used as indices in PHP arrays?

    "Since arrays in PHP are associative arrays, keys are not limited to integers. You can also use strings as keys to index elements.\n\n1 $arr = array();\n\n2 $arr[0] = 5;\n\n3 $arr[\"foo\"] = 10;\n\n4

  2. Can PHP array indices be non-contiguous?

    "Another aspect of PHP associative arrays is that integer indices need not be contiguous. For example,\n\n1 $arr = array();\n\n2 $arr[0] = 10;\n\n3 $arr[5] = 20;\n\nThe values at indices 1 through 4 a

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

    "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,

Strings as Indices | ComputerScienceOne | Bifalgorithm | Bifalgorithm