assoc_to_keyval()
average()
delete()
filter_keys()
filter_prefixed()
filter_recursive()
filter_suffixed()
flatten()
flatten_assoc()
get()
in_array_recursive()
insert()
insert_after_key()
insert_after_value()
insert_assoc()
insert_before_key()
insert_before_value()
is_assoc()
is_multi()
key_exists()
keyval_to_assoc()
merge()
merge_assoc()
multisort()
next_by_key()
next_by_value()
pluck()
prepend()
previous_by_key()
previous_by_value()
reindex()
remove_prefixed()
remove_suffixed()
replace_key()
reverse_flatten()
search()
set()
sort()
subset()
sum()
to_assoc()
unique()
The Arr class provides a few nice functions for making dealing with arrays easier
| package | Fuel |
|---|---|
| subpackage | Core |
assoc_to_keyval(array $assoc, string $key_field, string $val_field) : array
arraythe array to convert
stringthe field name of the key field
stringthe field name of the value field
\InvalidArgumentException |
|---|
arrayaverage(array $array) : \Fuel\Core\number
arraythe array containing the values
\Fuel\Core\numberthe average valuedelete(array $array, mixed $key) : mixed
arrayThe search array
mixedThe dot-notated key or array of keys
mixedfilter_keys(array $array, array $keys, bool $remove) : array
arraythe array to filter.
arraythe keys to filter
boolif true, removes the matched elements.
arrayfilter_prefixed(array $array, string $prefix, bool $remove_prefix) : array
arraythe array to filter.
stringprefix to filter on.
boolwhether to remove the prefix.
arrayfilter_recursive(array $array, callback $callback) : array
arraythe array to filter.
callbackthe callback that determines whether or not a value is filtered
arrayfilter_suffixed(array $array, string $suffix, bool $remove_suffix) : array
arraythe array to filter.
stringsuffix to filter on.
boolwhether to remove the suffix.
arrayflatten(array $array, string $glue, bool $reset, bool $indexed) : array
arraythe array to flatten
stringwhat to glue the keys together with
boolwhether to reset and start over on a new array
boolwhether to flatten only associative array's, or also indexed ones
arrayflatten_assoc(array $array, string $glue, bool $reset) : array
arraythe array to flatten
stringwhat to glue the keys together with
boolwhether to reset and start over on a new array
arrayget(array $array, mixed $key, string $default) : mixed
arrayThe search array
mixedThe dot-notated key or array of keys
stringThe default value
mixedin_array_recursive(mixed $needle, array $haystack, bool $strict) : bool
mixedwhat to search for
arrayarray to search in
bool
boolwhether the needle is found in the haystack.insert(array $original, array | mixed $value, int $pos) : bool
arraythe original array (by reference)
arraymixedthe value(s) to insert, if you want to insert an array it needs to be in an array itself
intthe numeric position at which to insert, negative to count from the end backwards
boolfalse when array shorter then $pos, otherwise trueinsert_after_key(array $original, array | mixed $value, string | int $key, bool $is_assoc) : bool
arraythe original array (by reference)
arraymixedthe value(s) to insert, if you want to insert an array it needs to be in an array itself
stringintthe key after which to insert
boolwhether the input is an associative array
boolfalse when key isn't found in the array, otherwise trueinsert_after_value(array $original, array | mixed $value, string | int $search, bool $is_assoc) : bool
arraythe original array (by reference)
arraymixedthe value(s) to insert, if you want to insert an array it needs to be in an array itself
stringintthe value after which to insert
boolwhether the input is an associative array
boolfalse when value isn't found in the array, otherwise trueinsert_assoc(array $original, array $values, int $pos) : bool
arraythe original array (by reference)
arraymixedthe value(s) to insert, if you want to insert an array it needs to be in an array itself
intthe numeric position at which to insert, negative to count from the end backwards
boolfalse when array shorter then $pos, otherwise trueinsert_before_key(array $original, array | mixed $value, string | int $key, bool $is_assoc) : bool
arraythe original array (by reference)
arraymixedthe value(s) to insert, if you want to insert an array it needs to be in an array itself
stringintthe key before which to insert
boolwhether the input is an associative array
boolfalse when key isn't found in the array, otherwise trueinsert_before_value(array $original, array | mixed $value, string | int $search, bool $is_assoc) : bool
arraythe original array (by reference)
arraymixedthe value(s) to insert, if you want to insert an array it needs to be in an array itself
stringintthe value after which to insert
boolwhether the input is an associative array
boolfalse when value isn't found in the array, otherwise trueis_assoc(array $arr) : bool
arraythe array to check
booltrue if its an assoc array, false if notis_multi(array $arr, bool $all_keys) : bool
arraythe array to check
boolif true, check that all elements are arrays
booltrue if its a multidimensional array, false if notkey_exists(array $array, mixed $key) : mixed
arrayThe search array
mixedThe dot-notated key or array of keys
mixedkeyval_to_assoc(array $array, string $key_field, string $val_field) : array
arraythe array to convert
stringthe field name of the key field
stringthe field name of the value field
\InvalidArgumentException |
|---|
arraymerge() : array
merge_assoc() : array
multisort(array $array, array $conditions, bool $ignore_case) : array
arraycollection of arrays/objects to sort
arraysorting conditions
boolwhether to sort case insensitive
arraynext_by_key(array $array, string $key, bool $get_value, bool $strict) : mixed
arraythe array containing the values
stringkey of the current entry to use as reference
boolif true, return the next value instead of the next key
boolif true, do a strict key comparison
mixedthe value in the array, null if there is no next value, or false if the key doesn't existnext_by_value(array $array, string $value, bool $get_value, bool $strict) : mixed
arraythe array containing the values
stringvalue of the current entry to use as reference
boolif true, return the next value instead of the next key
boolif true, do a strict key comparison
mixedthe value in the array, null if there is no next value, or false if the key doesn't existpluck(array $array, string $key, string $index) : array
arraycollection of arrays to pluck from
stringkey of the value to pluck
stringoptional return array index key, true for original index
arrayarray of plucked valuesprepend(array $arr, string | array $key, mixed $value)
Will overwrite if the value exists.
arraythe array to prepend to
stringarraythe key or array of keys and values
mixedthe value to prepend
previous_by_key(array $array, string $key, bool $get_value, bool $strict) : mixed
arraythe array containing the values
stringkey of the current entry to use as reference
boolif true, return the previous value instead of the previous key
boolif true, do a strict key comparison
mixedthe value in the array, null if there is no previous value, or false if the key doesn't existprevious_by_value(array $array, string $value, bool $get_value, bool $strict) : mixed
arraythe array containing the values
stringvalue of the current entry to use as reference
boolif true, return the previous value instead of the previous key
boolif true, do a strict key comparison
mixedthe value in the array, null if there is no previous value, or false if the key doesn't existreindex(array $arr) : array
arraythe array to reindex
arrayre-indexed arrayremove_prefixed(array $array, string $prefix) : array
arraythe array to remove from
stringprefix to filter on
arrayremove_suffixed(array $array, string $suffix) : array
arraythe array to remove from
stringsuffix to filter on
arrayreplace_key(array $source, array | string $replace, string $new_key) : array
arraythe array containing the key/value combinations
arraystringkey to replace or array containing the replacement keys
stringthe replacement key
arraythe array with the new keysreverse_flatten(array $array, string $glue) : array
arrayflattened array
stringglue used in flattening
arraythe unflattened arraysearch(array $array, mixed $value, string $default, bool $recursive, string $delimiter, bool $strict) : mixed
If $recursive is set to true, then the Arr::search() function will return a delimiter-notated key using $delimiter.
arrayThe search array
mixedThe searched value
stringThe default value
boolWhether to get keys recursive
stringThe delimiter, when $recursive is true
boolIf true, do a strict key comparison
mixedset(array $array, mixed $key, mixed $value) : void
arrayThe array to insert it into
mixedThe dot-notated key to set or array of keys
mixedThe value
sort(array $array, string $key, string $order, int $sort_flags) : array
| access | public |
|---|
arrayThe array to fetch from
stringThe key to sort by
stringThe order (asc or desc)
intThe php sort type flag
arraysubset(array $array, array $keys, mixed $default) : array
Returns $default for missing keys, as with Arr::get()
arraythe array containing the values
arraylist of keys (or indices) to return
mixedvalue of missing keys; default null
arrayAn array containing the same set of keys provided.sum(array $array, string $key) : \Fuel\Core\number
arraythe array containing the values
stringkey of the value to pluck
\Fuel\Core\numberthe sum valueto_assoc(string $arr) : array | null
The array given must have an even number of elements or null will be returned.
Arr::to_assoc(array('foo','bar'));
stringthe array to change
\BadMethodCallException |
|---|
arraynullthe new array or nullunique(array $arr) : array
It does not sort. First value is used.
arraythe array to dedup
arrayarray with only de-duped values