Built In Types: Arraykey

The type arraykey can represent any integer or string value. For example:

function process_key(arraykey $p): void {
  if ($p is int) {
    // we have an int
  } else {
    // we have a string
  }
}

Values of array or collection type can be indexed by int or string. Suppose, for example, an operation was performed on an array to extract the keys, but we didn't know the type of the key. As such, we are left with using mixed (which is way too loose) or doing some sort of duplicative code. Instead, we can use arraykey.

See the discussion of type refinement.

Was This Page Useful?
Thank You!
Thank You! If you'd like to share more feedback, please file an issue.