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 145
static ArraySet
combine(array $keys, array $values)
Combine two arrays, one as keys and one as values.
at line 160
ArraySet
contains(mixed $value, bool $strict = false)
Check if an array contains a specific value.
at line 172
ArraySet
crossJoin(array ...$arrays)
Compute the Cartesian product of multiple arrays.
at line 193
ArraySet
count()
Get the count of elements in the array.
at line 205
ArraySet
diff(array $array)
Get the difference between the current array and another array.
at line 217
ArraySet
dot(string $prepend = '')
Convert an array into dot notation.
at line 243
ArraySet
each(callable $callback)
Iterate over each item and apply a callback.
at line 257
ArraySet
except(array|string $keys)
Remove specified keys from the array.
at line 271
ArraySet
exists(string $key)
Determine if a key exists in an array.
at line 285
ArraySet
fill(int $start, int $count, mixed $value)
Fill an array with a specified value.
at line 297
ArraySet
filter(callable $callback)
Filters the array using a callback function.
at line 309
ArraySet
first(callable|null $callback = null)
Get the first element that matches a condition.
at line 329
ArraySet
firstKey()
Get the first key of the array.
at line 340
ArraySet
flatten()
Flatten a multi-dimensional array into a single level.
at line 355
ArraySet
flip()
Swap keys with values in the array.
at line 367
ArraySet
forget(string $key)
Remove a specific key from the array.
at line 380
ArraySet
get(string $key, mixed $default = null)
Get a value from the array using dot notation.
at line 403
ArraySet
has(string|int $key)
Check if a key exists in the array.
at line 415
ArraySet
hasAny(array|string $keys)
Determine if at least one of the given keys exists in the array.
at line 428
ArraySet
intersect(array $array)
Get the intersection of the current array and another array.
at line 440
ArraySet
intersectKeys(array $array)
Get elements whose keys exist in another array.
at line 452
ArraySet
implode(string $separator)
Join array elements with a string.
at line 464
ArraySet
isArray(mixed $value)
Check if the given value is an array.
at line 475
ArraySet
isEmpty()
Check if the array is empty.
at line 486
ArraySet
keys()
Get all keys of the array.
at line 498
ArraySet
keyBy(string $key)
Key an array by a specific field.
at line 509
ArraySet
krsort()
Sort the array by keys in descending order.
at line 520
ArraySet
ksort()
Sort the array by keys in ascending order.
at line 532
ArraySet
last(callable|null $callback = null)
Get the last element that matches a condition.
at line 553
ArraySet
lastKey()
Get the last key of the array.
at line 569
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 584
ArraySet
map(callable $callback)
Apply a callback function to each item in the array.
at line 596
ArraySet
mapRecursive(callable $callback)
Apply a recursive callback function to each element in the array.
at line 615
ArraySet
mapWithKeys(callable $callback)
Map an array using a callback that defines both keys and values.
at line 636
ArraySet
merge(array $array)
Merge the current array with another array.
at line 648
ArraySet
multisort(int $sortFlags = SORT_REGULAR)
Sort multiple arrays or multi-dimensional arrays.
at line 660
ArraySet
only(array|string $keys)
Return only the specified keys from the array.
at line 673
ArraySet
pad(int $size, mixed $value)
Pad an array to the specified length with a value.
at line 685
ArraySet
pluck(string $key)
Extract a specific key's values.
at line 697
ArraySet
prepend(mixed $value)
Prepend a value to the beginning of the array.
at line 710
ArraySet
pull(string $key, mixed $default = null)
Remove and return a value from the array.
at line 723
ArraySet
push(mixed ...$values)
Add one or more values to the array.
at line 735
ArraySet
random(int|null $number = null)
Get a random value or multiple values from the array.
at line 750
ArraySet
reduce(callable $callback, mixed $initial = null)
Reduce the array to a single value using a callback.
at line 762
ArraySet
replace(array $array)
Replace values in the array with values from another array.
at line 773
mixed
result()
Retrieve the result of the last operation.
at line 783
ArraySet
reverse()
Reverse the order of the array.
at line 794
ArraySet
rsort()
Sort the array in descending order.
at line 806
ArraySet
search(mixed $value)
Search for a value in the array and return its key.
at line 819
ArraySet
set(string $key, mixed $value)
Set a value in the array using dot notation.
at line 840
ArraySet
shift()
Remove and return the first item from the array.
at line 851
ArraySet
shuffle()
Shuffle the elements of the array.
at line 862
ArraySet
shuffleAssociative()
Shuffle an array while preserving keys.
at line 877
ArraySet
slice(int $offset, int|null $length = null)
Extract a slice of the array.
at line 889
ArraySet
sort(int $sortFlags = SORT_REGULAR)
Sort the array in ascending order.
at line 903
ArraySet
splice(int $offset, int|null $length = null, array $replacement = [])
Remove and replace a portion of the array.
at line 916
ArraySet
udiff(array $array, callable $callback)
Compute the difference between arrays using a custom comparison function.
at line 927
ArraySet
unique()
Remove duplicate values from the array.
at line 939
ArraySet
usort(callable $callback)
Sort the array using a user-defined comparison function.
at line 950
ArraySet
values()
Get all values of the array.
at line 962
ArraySet
walk(callable $callback)
Apply a user function to every item in the array.
at line 974
ArraySet
walkRecursive(callable $callback)
Recursively apply a user function to every item in the array.
at line 986
ArraySet
wrap(mixed $value)
Wrap a value in an array if it is not already an array.
at line 1002
ArraySet
where(callable $callback)
Filter the array using a callback function.