Documentation

Common
in package

Table of Contents

find()  : mixed
Find one or more elements inside a collection where the path resolves to the value provided.
get()  : mixed
Get a value from a collection using a path.
isCollection()  : mixed
remove()  : bool
Remove an element by key from the collection
set()  : mixed
Set a value inside a collection using a path.

Methods

find()

Find one or more elements inside a collection where the path resolves to the value provided.

public static find(mixed $collection, string $key, mixed $value[, bool $multiple = false ]) : mixed

Eg: Common::find([['name' => 'john'], ['name' => 'joe']], 'name', 'john') -> resolves to ['name' => 'john']

Multiple Example: $collection = [ ['name' => 'john'], ['name' => 'john'], ['name' => 'joe'] ];

 Common::find($collection, 'name', 'john')
 -> Resolves to:
     [
         ['name' => 'john'],
         ['name' => 'john']
     ]
Parameters
$collection : mixed
$key : string
$value : mixed
$multiple : bool = false
Return values
mixed

get()

Get a value from a collection using a path.

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

Eg: Common::get($collection, 'user->card->number) will look for a number, inside the card, inside the user. if the path doesn't exist, a default value will be returned.

Parameters
$collection : array<string|int, mixed> = []
$key : null = null
$default : null = null
Return values
mixed

isCollection()

public static isCollection(mixed $var) : mixed
Parameters
$var : mixed
Return values
mixed

remove()

Remove an element by key from the collection

public static remove(mixed &$collection, string $key) : bool

If something was unset, returns true, false otherwise.

Parameters
$collection : mixed
$key : string
Return values
bool

set()

Set a value inside a collection using a path.

public static set(mixed $collection, mixed $key[, null $value = null ][, string $container = 'array' ]) : mixed

Eg: Common::set($collection, 'user->card->number) if collection doesn't have the 'user' attribute this will create an array, with the card array and the number value inside that array.

Parameters
$collection : mixed
$key : mixed
$value : null = null
$container : string = 'array'
Return values
mixed

Search results