Arr
class Arr (View source)
Traits
Properties
static protected array | $macros | The registered string macros. |
from Macroable |
Methods
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Determine whether the given value is array accessible.
Add an element to an array using "dot" notation if it doesn't exist.
Collapse an array of arrays into a single array.
Cross join the given arrays, returning all possible permutations.
Divide an array into two arrays. One with keys and the other with values.
Flatten a multi-dimensional associative array with dots.
Convert a flatten "dot" notation array into an expanded array.
Get all of the given array except for a specified array of keys.
Determine if the given key exists in the provided array.
Return the first element in an array passing a given truth test.
Return the last element in an array passing a given truth test.
Take the first or last {$limit} items from an array.
Flatten a multi-dimensional array into a single level.
Remove one or many array items from a given array using "dot" notation.
Get an item from an array using "dot" notation.
Check if an item or items exist in an array using "dot" notation.
Determine if any of the keys exist in an array using "dot" notation.
Determines if an array is associative.
Determines if an array is a list.
Join all items using a string. The final items can use a separate glue string.
Key an associative array by a field or using a callback.
Prepend the key names of an associative array.
Get a subset of the items from the given array.
Select an array of values from an array.
Pluck an array of values from an array.
Explode the "value" and "key" arguments passed to "pluck".
Run a map over each of the items in the array.
No description
Push an item onto the beginning of an array.
Get a value from the array, and remove it.
Convert the array into a query string.
Get one or a specified number of random values from an array.
Set an array item to a given value using "dot" notation.
Shuffle the given array and return the result.
Sort the array using the given callback or "dot" notation.
Sort the array in descending order using the given callback or "dot" notation.
Recursively sort an array by keys and values.
Recursively sort an array by keys and values in descending order.
Conditionally compile classes from an array into a CSS class list.
Conditionally compile styles from an array into a style list.
Filter the array using the given callback.
Filter items where the value is not null.
If the given value is not an array and not null, wrap it in one.
Details
static void
macro(string $name, object|callable $macro)
Register a custom macro.
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
static bool
hasMacro(string $name)
Checks if macro is registered.
static void
flushMacros()
Flush the existing macros.
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
static bool
accessible(mixed $value)
Determine whether the given value is array accessible.
static array
add(array $array, string|int|float $key, mixed $value)
Add an element to an array using "dot" notation if it doesn't exist.
static array
collapse(iterable $array)
Collapse an array of arrays into a single array.
static array
crossJoin(iterable ...$arrays)
Cross join the given arrays, returning all possible permutations.
static array
divide(array $array)
Divide an array into two arrays. One with keys and the other with values.
static array
dot(iterable $array, string $prepend = '')
Flatten a multi-dimensional associative array with dots.
static array
undot(iterable $array)
Convert a flatten "dot" notation array into an expanded array.
static array
except(array $array, array|string|int|float $keys)
Get all of the given array except for a specified array of keys.
static bool
exists(ArrayAccess|array $array, string|int $key)
Determine if the given key exists in the provided array.
static mixed
first(iterable $array, callable|null $callback = null, mixed $default = null)
Return the first element in an array passing a given truth test.
static mixed
last(array $array, callable|null $callback = null, mixed $default = null)
Return the last element in an array passing a given truth test.
static array
take(array $array, int $limit)
Take the first or last {$limit} items from an array.
static array
flatten(iterable $array, int $depth = INF)
Flatten a multi-dimensional array into a single level.
static void
forget(array $array, array|string|int|float $keys)
Remove one or many array items from a given array using "dot" notation.
static mixed
get(ArrayAccess|array $array, string|int|null $key, mixed $default = null)
Get an item from an array using "dot" notation.
static bool
has(ArrayAccess|array $array, string|array $keys)
Check if an item or items exist in an array using "dot" notation.
static bool
hasAny(ArrayAccess|array $array, string|array $keys)
Determine if any of the keys exist in an array using "dot" notation.
static bool
isAssoc(array $array)
Determines if an array is associative.
An array is "associative" if it doesn't have sequential numerical keys beginning with zero.
static bool
isList(array $array)
Determines if an array is a list.
An array is a "list" if all array keys are sequential integers starting from 0 with no gaps in between.
static string
join(array $array, string $glue, string $finalGlue = '')
Join all items using a string. The final items can use a separate glue string.
static array
keyBy(array $array, callable|array|string $keyBy)
Key an associative array by a field or using a callback.
static array
prependKeysWith(array $array, string $prependWith)
Prepend the key names of an associative array.
static array
only(array $array, array|string $keys)
Get a subset of the items from the given array.
static array
select(array $array, array|string $keys)
Select an array of values from an array.
static array
pluck(iterable $array, string|array|int|null $value, string|array|null $key = null)
Pluck an array of values from an array.
static protected array
explodePluckParameters(string|array $value, string|array|null $key)
Explode the "value" and "key" arguments passed to "pluck".
static array
map(array $array, callable $callback)
Run a map over each of the items in the array.
static
mapWithKeys(array $array, callable $callback)
No description
static array
prepend(array $array, mixed $value, mixed $key = null)
Push an item onto the beginning of an array.
static mixed
pull(array $array, string|int $key, mixed $default = null)
Get a value from the array, and remove it.
static string
query(array $array)
Convert the array into a query string.
static mixed
random(array $array, int|null $number = null, bool $preserveKeys = false)
Get one or a specified number of random values from an array.
static array
set(array $array, string|int|null $key, mixed $value)
Set an array item to a given value using "dot" notation.
If no key is given to the method, the entire array will be replaced.
static array
shuffle(array $array, int|null $seed = null)
Shuffle the given array and return the result.
static array
sort(array $array, callable|array|string|null $callback = null)
Sort the array using the given callback or "dot" notation.
static array
sortDesc(array $array, callable|array|string|null $callback = null)
Sort the array in descending order using the given callback or "dot" notation.
static array
sortRecursive(array $array, int $options = SORT_REGULAR, bool $descending = false)
Recursively sort an array by keys and values.
static array
sortRecursiveDesc(array $array, int $options = SORT_REGULAR)
Recursively sort an array by keys and values in descending order.
static string
toCssClasses(array $array)
Conditionally compile classes from an array into a CSS class list.
static string
toCssStyles(array $array)
Conditionally compile styles from an array into a style list.
static array
where(array $array, callable $callback)
Filter the array using the given callback.
static array
whereNotNull(array $array)
Filter items where the value is not null.
static array
wrap(mixed $value)
If the given value is not an array and not null, wrap it in one.