Download the PHP package bayfrontmedia/php-array-helpers without Composer
On this page you can find all versions of the php package bayfrontmedia/php-array-helpers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bayfrontmedia/php-array-helpers
More information about bayfrontmedia/php-array-helpers
Files in bayfrontmedia/php-array-helpers
Package php-array-helpers
Short Description Helper class to provide useful array functions.
License MIT
Homepage https://github.com/bayfrontmedia/php-array-helpers
Informations about the package php-array-helpers
PHP array helpers
PHP helper class to provide useful array functions.
- License
- Author
- Requirements
- Installation
- Usage
License
This project is open source and available under the MIT License.
Author
Requirements
- PHP
^8.0
Installation
Usage
- dot
- undot
- set
- has
- get
- pluck
- forget
- except
- only
- missing
- isMissing
- multisort
- renameKeys
- order
- query
- getAnyValues
- hasAnyValues
- hasAllValues
dot
Description:
Converts a multidimensional array to a single depth "dot" notation array, optionally prepending a string to each array key.
The key values will never be an array, even if empty. Empty arrays will be dropped.
Parameters:
$array
(array): Original array$prepend = ''
(string): String to prepend
Returns:
- (array)
Example:
undot
Description:
Converts array in "dot" notation to a standard multidimensional array.
Parameters:
$array
(array): Array in "dot" notation
Returns:
- (array)
Example:
set
Description:
Set an array item to a given value using "dot" notation.
Parameters:
$array
(array): Original array$key
(string): Key to set in "dot" notation$value
(mixed): Value of key
Returns:
- (void)
Example:
has
Description:
Checks if array key exists and not null using "dot" notation.
Parameters:
$array
(array): Original array$key
(string): Key to check in "dot" notation
Returns:
- (bool)
Example:
get
Description:
Get an item from an array using "dot" notation, returning an optional default value if not found.
Parameters:
$array
(array): Original array$key
(string): Key to return in "dot" notation$default = NULL
(mixed): Default value to return
Returns:
- (mixed)
Example:
pluck
Description:
Returns an array of values for a given key from an array using "dot" notation.
Parameters:
$array
(array): Original array$value
(string): Value to return in "dot" notation$key = NULL
(string|null): Optionally how to key the returned array in "dot" notation
Returns:
- (array)
Example:
forget
Description:
Remove a single key, or an array of keys from a given array using "dot" notation.
Parameters:
$array
(array): Original array$keys
(string|array): Key(s) to forget in "dot" notation
Returns:
- (void)
Example:
except
Description:
Returns the original array except given key(s).
Parameters:
$array
(array): Original array$keys
(string|array): Key(s) to remove
Returns:
- (array)
Example:
only
Description:
Returns only desired key(s) from an array.
Parameters:
$array
(array): Original array$keys
(string|array): Key(s) to return
Returns:
- (array)
Example:
missing
Description:
Returns array of missing keys from the original array, or an empty array if none are missing.
Parameters:
$array
(array): Original array$keys
(array): Key(s) to check
Returns:
- (array)
Example:
isMissing
Description:
Checks if keys are missing from the original array.
Parameters:
$array
(array): Original array$keys
(array): Key(s) to check
Returns:
- (bool)
Example:
multisort
Description:
Sort a multidimensional array by a given key in ascending (optionally, descending) order.
Parameters:
$array
(array): Original array$key
(string): Key name to sort by$descending = false
(bool): Sort descending
Returns:
- (array)
Example:
renameKeys
Description:
Rename array keys while preserving their order.
Parameters:
$array
(array): Original array$keys
(array): Key/value pairs to rename
Returns:
- (array)
Example:
order
Description:
Order an array based on an array of keys.
Keys from the $order
array which do not exist in the original array will be ignored.
Parameters:
$array
(array): Original array$order
(array): Array of keys in the order to be returned
Returns:
- (array)
Example:
The above example will return the following array:
query
Description:
Convert array into a query string.
Parameters:
$array
(array): Original array
Returns:
- (string)
Example:
getAnyValues
Description:
Return an array of values which exist in a given array.
Parameters:
$array
(array)$values
(array)
Returns:
- (array)
Example:
hasAnyValues
Description:
Do any values exist in a given array.
Parameters:
$array
(array)$values
(array)
Returns:
- (bool)
Example:
hasAllValues
Description:
Do all values exist in a given array.
Parameters:
$array
(array)$values
(array)
Returns:
- (bool)
Example: