Documentation

ArrayValue
in package

FinalYes

Get a value from an array given a key. If the array key exists, throws if it is not the expected type. Can throw, return null, or return a default if the array key does not exist.

Table of Contents

Methods

get()  : T
getOptional()  : T|null
getOrDefault()  : T)

Methods

get()

public static get(array<string|int, mixed> $arr, string|int $key, Type<string|int, T> $type) : T
Parameters
$arr : array<string|int, mixed>
$key : string|int
$type : Type<string|int, T>
Tags
template
Return values
T

getOptional()

public static getOptional(array<string|int, mixed> $arr, string|int $key, Type<string|int, T> $type) : T|null
Parameters
$arr : array<string|int, mixed>
$key : string|int
$type : Type<string|int, T>
Tags
template
Return values
T|null

getOrDefault()

public static getOrDefault(array<string|int, mixed> $arr, string|int $key, Type<string|int, T> $type, T|null $default) : T)
Parameters
$arr : array<string|int, mixed>
$key : string|int
$type : Type<string|int, T>
$default : T|null
Tags
template
Return values
T)

        
On this page

Search results