Documentation

Arr
in package

Table of Contents

Methods

exists()  : bool
Check if a key exists in an array
forget()  : void
Remove a value from an array using "dot" notation.
get()  : mixed
Get a value from an array using "dot" notation
pull()  : mixed
Retrieve a value from an array using "dot" notation and remove it.

Methods

exists()

Check if a key exists in an array

public static exists(mixed $array, string $key) : bool
Parameters
$array : mixed

The array to check

$key : string

The key to check for existence

Return values
bool

True if the key exists, otherwise false

forget()

Remove a value from an array using "dot" notation.

public static forget(array<string|int, mixed> &$array, string $key) : void

This method removes a value from the array using "dot" notation, which allows you to specify the nested array key using dot syntax. For example, if you have an array like ['foo' => ['bar' => 'baz']], you can remove the 'bar' key by calling forget($array, 'foo.bar').

Parameters
$array : array<string|int, mixed>

The array to modify

$key : string

The key to remove (supports "dot" notation)

get()

Get a value from an array using "dot" notation

public static get(array<string|int, mixed> $array, string $key[, mixed $default = null ]) : mixed
Parameters
$array : array<string|int, mixed>

The array to search

$key : string

The key to retrieve, with dot notation for nested keys

$default : mixed = null

(optional) The default value to return if the key is not found

Return values
mixed

The value if found, otherwise the default value or null

pull()

Retrieve a value from an array using "dot" notation and remove it.

public static pull(array<string|int, mixed> &$array, string $key[, mixed $default = null ]) : mixed

This method retrieves a value from the array using "dot" notation, which allows you to specify the nested array key using dot syntax. For example, if you have an array like ['foo' => ['bar' => 'baz']], you can pull the value of 'bar' by calling pull($array, 'foo.bar'). The specified key is then removed from the array.

Parameters
$array : array<string|int, mixed>

The array to search

$key : string

The key to retrieve (supports "dot" notation)

$default : mixed = null

The default value to return if the key is not found

Return values
mixed

The retrieved value or the default value


        
On this page

Search results