Pionia Core

Arrayable
in package
Uses Microable

Table of Contents

Properties

$macros  : array<string|int, mixed>
$array  : array<string|int, mixed>
The array to be manipulated

Methods

__call()  : mixed
Dynamically handle calls to the class.
__callStatic()  : mixed
Dynamically handle calls to the class.
__construct()  : mixed
__get()  : mixed
__isset()  : mixed
__set()  : mixed
__toString()  : string
__unset()  : mixed
add()  : Arrayable
Add a key value pair to the array If only the key is provided, the key will be the value
addAfter()  : static
addAtKey()  : $this
Adds the $value to the current value of $key.
addBefore()  : static
all()  : array<string|int, mixed>
arrayType()  : string
Get the type of the array
at()  : mixed
Get the value at a certain index
chunk()  : Arrayable
Chunk the array
each()  : Arrayable
Each through the array
filter()  : Arrayable
Filter the array
first()  : false|mixed
Get the first item in the array
flush()  : $this
Reset the array
flushMacros()  : void
Remove all the macros we had registered
get()  : mixed
Get an item from the array
getA()  : mixed
getArray()  : array<string|int, mixed>|null
getArrayable()  : Arrayable|null
getBool()  : bool|null
getFloat()  : float|null
getInt()  : int|null
getJson()  : false|string|null
getNegativeInteger()  : int|null
getOrThrow()  : mixed
getPositiveInteger()  : int|null
getString()  : string|null
has()  : bool
Check if the array has a key
hasMacro()  : bool
Check if we have a method in the balonables
isAssoc()  : bool
Checks if an array is associative
isEmpty()  : bool
Checks if the array is empty
isFilled()  : bool
isMixed()  : bool
Checks if an array has both numeric and string keys
keys()  : array<string|int, mixed>
Get the keys of the array
keysToLowerCase()  : $this
Convert the keys of the array to lowercase
keysToUpperCase()  : $this
Convert the keys of the array to uppercase
last()  : false|mixed
Get the last item in the array
macro()  : void
Add a new mixable to the macros
map()  : Arrayable
Map through the array
mapWithKeys()  : Arrayable
Map through the array and flatten the result to a single array of values by using the callback
merge()  : Arrayable
Merge a whole into the current array
mixin()  : void
Mix another object into the class.
only()  : Arrayable
Get a subset of the items from the given array.
pop()  : mixed
reduce()  : Arrayable
Reduce the array
remove()  : Arrayable
Remove an item from the array
replace()  : static
reverse()  : Arrayable
Reverse the array
set()  : $this
Set an item in the array by key and value
shift()  : mixed
size()  : int
Get the size of the array
slice()  : $this
Slice the array
sort()  : Arrayable
Sort the array
sortKeys()  : Arrayable
Sort the keys of the array
sortValues()  : Arrayable
Sort the values of the array
toArray()  : array<string|int, mixed>
Convert the arrayable object to an array
toArrayable()  : Arrayable
toJson()  : string
Convert the arrayable to json
type()  : string
Return the type of the underlying array object
unshift()  : static
values()  : array<string|int, mixed>
Get the values of the array
valuesToLowerCase()  : Arrayable
Convert the values of the array to lowercase
where()  : Arrayable
Filter the array using the given callback.

Properties

$macros

protected static array<string|int, mixed> $macros = []

$array

The array to be manipulated

private array<string|int, mixed> $array = []

Methods

__call()

Dynamically handle calls to the class.

public __call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string
$parameters : array<string|int, mixed>
Tags
throws
BadMethodCallException

__callStatic()

Dynamically handle calls to the class.

public static __callStatic(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string
$parameters : array<string|int, mixed>
Tags
throws
BadMethodCallException

__construct()

public __construct([array<string|int, mixed> $array = [] ]) : mixed
Parameters
$array : array<string|int, mixed> = []

__get()

public __get(mixed $name) : mixed
Parameters
$name : mixed

__isset()

public __isset(mixed $name) : mixed
Parameters
$name : mixed

__set()

public __set(mixed $name, mixed $value) : mixed
Parameters
$name : mixed
$value : mixed

__toString()

public __toString() : string
Return values
string

__unset()

public __unset(mixed $name) : mixed
Parameters
$name : mixed

add()

Add a key value pair to the array If only the key is provided, the key will be the value

public add(string $key[, mixed|null $value = null ]) : Arrayable
Parameters
$key : string
$value : mixed|null = null
Return values
Arrayable

addAfter()

public addAfter(mixed $positionKey, mixed $key[, mixed $value = null ]) : static
Parameters
$positionKey : mixed
$key : mixed
$value : mixed = null
Return values
static

addAtKey()

Adds the $value to the current value of $key.

public addAtKey(string $key, mixed $value) : $this

If the value is numeric, it will be added to the current value If the value is a string, it will be concatenated to the current value If the value is an array, it will be merged with the current value

Parameters
$key : string
$value : mixed
Return values
$this

addBefore()

public addBefore(string $positionKey, string $key[, mixed $value = null ]) : static
Parameters
$positionKey : string
$key : string
$value : mixed = null
Return values
static

all()

public all() : array<string|int, mixed>
Return values
array<string|int, mixed>

arrayType()

Get the type of the array

public arrayType([array<string|int, mixed>|null $arr = null ]) : string
Parameters
$arr : array<string|int, mixed>|null = null
Return values
string

at()

Get the value at a certain index

public at(int $index) : mixed
Parameters
$index : int

chunk()

Chunk the array

public chunk(int $size[, bool $preserve_keys = false ]) : Arrayable
Parameters
$size : int
$preserve_keys : bool = false
Return values
Arrayable

filter()

Filter the array

public filter([callable|null $callback = null ]) : Arrayable
Parameters
$callback : callable|null = null
Return values
Arrayable

first()

Get the first item in the array

public first() : false|mixed
Return values
false|mixed

flush()

Reset the array

public flush() : $this
Return values
$this

flushMacros()

Remove all the macros we had registered

public static flushMacros() : void

get()

Get an item from the array

public get(string|null $name[, mixed|null $default = null ]) : mixed

If checkUpperAndLower is set to true, the method will check for uppercase and lowercase cases

Parameters
$name : string|null
$default : mixed|null = null

getA()

public getA(string $key, string $className) : mixed
Parameters
$key : string
$className : string
Tags
throws
Exception

getArray()

public getArray(string $key) : array<string|int, mixed>|null
Parameters
$key : string
Return values
array<string|int, mixed>|null

getBool()

public getBool(string $key) : bool|null
Parameters
$key : string
Return values
bool|null

getFloat()

public getFloat(string $key) : float|null
Parameters
$key : string
Return values
float|null

getInt()

public getInt(string $key) : int|null
Parameters
$key : string
Return values
int|null

getJson()

public getJson(mixed $key) : false|string|null
Parameters
$key : mixed
Tags
throws
JsonException
Return values
false|string|null

getNegativeInteger()

public getNegativeInteger(string $key) : int|null
Parameters
$key : string
Return values
int|null

getOrThrow()

public getOrThrow(string $key[, Throwable|string|null $exception = null ]) : mixed
Parameters
$key : string
$exception : Throwable|string|null = null
Tags
throws
Throwable

getPositiveInteger()

public getPositiveInteger(string $key) : int|null
Parameters
$key : string
Return values
int|null

getString()

public getString(string $key) : string|null
Parameters
$key : string
Return values
string|null

has()

Check if the array has a key

public has(string $key) : bool
Parameters
$key : string
Return values
bool

hasMacro()

Check if we have a method in the balonables

public static hasMacro(string $name) : bool
Parameters
$name : string
Return values
bool

isAssoc()

Checks if an array is associative

public isAssoc([array<string|int, mixed>|null $arr = null ]) : bool
Parameters
$arr : array<string|int, mixed>|null = null
Return values
bool

isEmpty()

Checks if the array is empty

public isEmpty() : bool
Return values
bool

isFilled()

public isFilled() : bool
Return values
bool

isMixed()

Checks if an array has both numeric and string keys

public isMixed([array<string|int, mixed>|null $arr = null ]) : bool
Parameters
$arr : array<string|int, mixed>|null = null
Return values
bool

keys()

Get the keys of the array

public keys() : array<string|int, mixed>
Return values
array<string|int, mixed>

keysToLowerCase()

Convert the keys of the array to lowercase

public keysToLowerCase() : $this
Return values
$this

keysToUpperCase()

Convert the keys of the array to uppercase

public keysToUpperCase() : $this
Return values
$this

last()

Get the last item in the array

public last() : false|mixed
Return values
false|mixed

macro()

Add a new mixable to the macros

public static macro(string $key,  $value) : void
Parameters
$key : string
$value :

mapWithKeys()

Map through the array and flatten the result to a single array of values by using the callback

public mapWithKeys(callable $callback) : Arrayable
Parameters
$callback : callable
Tags
example
$this->arrayable->merge([
[
'first' => 'John',
'last' => 'Doe',
'age' => 22
],
[
'first' => 'Kate',
'last' => 'Middleton',
'age' => 30
],
[
'first' => 'Jane',
'last' => 'Doe',
'age' => 20
]
]);

$map = $this->arrayable->mapWithKeys(function ($item) {
return [$item['first'] => $item['age']];
});
dd($map->toArray());

// Output
[
"John" => 22
"Kate" => 30
"Jane" => 20
]
Return values
Arrayable

merge()

Merge a whole into the current array

public merge(array<string|int, mixed> $array) : Arrayable
Parameters
$array : array<string|int, mixed>
Return values
Arrayable

mixin()

Mix another object into the class.

public static mixin(object $mixin[, bool $replace = true ]) : void
Parameters
$mixin : object
$replace : bool = true
Tags
throws
ReflectionException

only()

Get a subset of the items from the given array.

public only([array<string|int, mixed>|string|null $keys = null ]) : Arrayable
Parameters
$keys : array<string|int, mixed>|string|null = null
Return values
Arrayable

reduce()

Reduce the array

public reduce(callable $callback[, null $initial = null ]) : Arrayable
Parameters
$callback : callable
$initial : null = null
Return values
Arrayable

replace()

public replace(string $key[, mixed $value = null ]) : static
Parameters
$key : string
$value : mixed = null
Return values
static

set()

Set an item in the array by key and value

public set(string $key, mixed $value) : $this
Parameters
$key : string
$value : mixed
Return values
$this

size()

Get the size of the array

public size() : int
Return values
int

slice()

Slice the array

public slice(int $offset[, int|null $length = null ][,  $preserve_keys = false ]) : $this
Parameters
$offset : int
$length : int|null = null
$preserve_keys : = false
Return values
$this

sortKeys()

Sort the keys of the array

public sortKeys(callable $callback) : Arrayable
Parameters
$callback : callable
Return values
Arrayable

sortValues()

Sort the values of the array

public sortValues(callable $callback) : Arrayable
Parameters
$callback : callable
Return values
Arrayable

toArray()

Convert the arrayable object to an array

public toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

toArrayable()

public static toArrayable(array<string|int, mixed> $array) : Arrayable
Parameters
$array : array<string|int, mixed>
Return values
Arrayable

toJson()

Convert the arrayable to json

public toJson() : string
Return values
string

type()

Return the type of the underlying array object

public type() : string
Return values
string

unshift()

public unshift(array<string|int, mixed> $value) : static
Parameters
$value : array<string|int, mixed>
Return values
static

values()

Get the values of the array

public values() : array<string|int, mixed>
Return values
array<string|int, mixed>

where()

Filter the array using the given callback.

public where(callable $callback) : Arrayable
Parameters
$callback : callable
Return values
Arrayable

        
On this page

Search results