ArraySet
class ArraySet
Array utility class with functions for both chainable operations.
Properties
| protected array | $items | Items for array. |
|
| protected mixed | $lastResult | The last result. |
Methods
Constructor to initialize the array.
Get all items in the array.
Combine two arrays, one as keys and one as values.
Determine if at least one of the given keys exists in the array.
Get elements whose keys exist in another array.
Apply a recursive callback function to each element in the array.
Map an array using a callback that defines both keys and values.
Reduce the array to a single value using a callback.
Retrieve the result of the last operation.
Shuffle an array while preserving keys.
Remove and replace a portion of the array.
Compute the difference between arrays using a custom comparison function.
Recursively apply a user function to every item in the array.
Details
at line 29
__construct(array $items = [])
Constructor to initialize the array.
at line 42
ArraySet
add(string $key, mixed $value)
Add a value to the array if the key does not exist.
at line 55
array
all()
Get all items in the array.
at line 68
ArraySet
asort()
Sort the array while maintaining index association.
This method sorts the array in ascending order while preserving the original keys.
at line 82
ArraySet
arsort()
Sort the array in descending order while maintaining index association.
This method sorts the array in descending order while preserving the original keys.
at line 94
ArraySet
chunk(int $size)
Split an array into chunks.
at line 105
ArraySet
clear()
Clear all items in the array.
at line 116
ArraySet
collapse()
Collapse a multi-dimensional array into a single level.
at line 132
ArraySet
column(string|int $columnKey)
Extract a single column from a multi-dimensional array.
at line 148
static ArraySet
combine(array $keys, array $values)
Combine two arrays, one as keys and one as values.
at line 163
ArraySet
contains(mixed $value, bool $strict = false)
Check if an array contains a specific value.
at line 175
ArraySet
crossJoin(array ...$arrays)
Compute the Cartesian product of multiple arrays.
at line 196
ArraySet
count()
Get the count of elements in the array.
at line 208
ArraySet
diff(array $array)
Get the difference between the current array and another array.
at line 220
ArraySet
dot(string $prepend = '')
Convert an array into dot notation.
at line 246
ArraySet
each(callable $callback)
Iterate over each item and apply a callback.
at line 260
ArraySet
except(array|string $keys)
Remove specified keys from the array.
at line 274
ArraySet
exists(string $key)
Determine if a key exists in an array.
at line 288
ArraySet
fill(int $start, int $count, mixed $value)
Fill an array with a specified value.
at line 300
ArraySet
filter(callable $callback)
Filters the array using a callback function.
at line 312
ArraySet
first(callable|null $callback = null)
Get the first element that matches a condition.
at line 332
ArraySet
firstKey()
Get the first key of the array.
at line 343
ArraySet
flatten()
Flatten a multi-dimensional array into a single level.
at line 358
ArraySet
flip()
Swap keys with values in the array.
at line 370
ArraySet
forget(string $key)
Remove a specific key from the array.
at line 383
ArraySet
get(string $key, mixed $default = null)
Get a value from the array using dot notation.
at line 406
ArraySet
has(string|int $key)
Check if a key exists in the array.
at line 418
ArraySet
hasAny(array|string $keys)
Determine if at least one of the given keys exists in the array.
at line 431
ArraySet
intersect(array $array)
Get the intersection of the current array and another array.
at line 443
ArraySet
intersectKeys(array $array)
Get elements whose keys exist in another array.
at line 455
ArraySet
implode(string $separator)
Join array elements with a string.
at line 467
ArraySet
isArray(mixed $value)
Check if the given value is an array.
at line 478
ArraySet
isEmpty()
Check if the array is empty.
at line 489
ArraySet
keys()
Get all keys of the array.
at line 501
ArraySet
keyBy(string $key)
Key an array by a specific field.
at line 512
ArraySet
krsort()
Sort the array by keys in descending order.
at line 523
ArraySet
ksort()
Sort the array by keys in ascending order.
at line 535
ArraySet
last(callable|null $callback = null)
Get the last element that matches a condition.
at line 556
ArraySet
lastKey()
Get the last key of the array.
at line 572
static ArraySet
make(mixed $items = [])
Create a new Arr instance from an array or a single value.
This function ensures that the provided input is always treated as an array.
If a non-array value (e.g., null, string, int) is passed, it wraps
it into an array automatically.
at line 587
ArraySet
map(callable $callback)
Apply a callback function to each item in the array.
at line 599
ArraySet
mapRecursive(callable $callback)
Apply a recursive callback function to each element in the array.
at line 618
ArraySet
mapWithKeys(callable $callback)
Map an array using a callback that defines both keys and values.
at line 639
ArraySet
merge(array $array)
Merge the current array with another array.
at line 651
ArraySet
multisort(int $sortFlags = SORT_REGULAR)
Sort multiple arrays or multi-dimensional arrays.
at line 663
ArraySet
only(array|string $keys)
Return only the specified keys from the array.
at line 676
ArraySet
pad(int $size, mixed $value)
Pad an array to the specified length with a value.
at line 688
ArraySet
pluck(string $key)
Extract a specific key's values.
at line 700
ArraySet
prepend(mixed $value)
Prepend a value to the beginning of the array.
at line 713
ArraySet
pull(string $key, mixed $default = null)
Remove and return a value from the array.
at line 726
ArraySet
push(mixed ...$values)
Add one or more values to the array.
at line 738
ArraySet
random(int|null $number = null)
Get a random value or multiple values from the array.
at line 753
ArraySet
reduce(callable $callback, mixed $initial = null)
Reduce the array to a single value using a callback.
at line 765
ArraySet
replace(array $array)
Replace values in the array with values from another array.
at line 776
mixed
result()
Retrieve the result of the last operation.
at line 786
ArraySet
reverse()
Reverse the order of the array.
at line 797
ArraySet
rsort()
Sort the array in descending order.
at line 809
ArraySet
search(mixed $value)
Search for a value in the array and return its key.
at line 822
ArraySet
set(string $key, mixed $value)
Set a value in the array using dot notation.
at line 843
ArraySet
shift()
Remove and return the first item from the array.
at line 854
ArraySet
shuffle()
Shuffle the elements of the array.
at line 865
ArraySet
shuffleAssociative()
Shuffle an array while preserving keys.
at line 880
ArraySet
slice(int $offset, int|null $length = null)
Extract a slice of the array.
at line 892
ArraySet
sort(int $sortFlags = SORT_REGULAR)
Sort the array in ascending order.
at line 906
ArraySet
splice(int $offset, int|null $length = null, array $replacement = [])
Remove and replace a portion of the array.
at line 919
ArraySet
udiff(array $array, callable $callback)
Compute the difference between arrays using a custom comparison function.
at line 930
ArraySet
unique()
Remove duplicate values from the array.
at line 942
ArraySet
usort(callable $callback)
Sort the array using a user-defined comparison function.
at line 953
ArraySet
values()
Get all values of the array.
at line 965
ArraySet
walk(callable $callback)
Apply a user function to every item in the array.
at line 977
ArraySet
walkRecursive(callable $callback)
Recursively apply a user function to every item in the array.
at line 989
ArraySet
wrap(mixed $value)
Wrap a value in an array if it is not already an array.
at line 1005
ArraySet
where(callable $callback)
Filter the array using a callback function.