ArrayHelper
ArrayHelper is an array utility class for doing all sorts of odds and ends with arrays.
since |
1.0 |
---|---|
package |
Joomla Framework |
Methods
__construct
Private constructor to prevent instantiation of this class
__construct() : mixed
since |
1.0 |
---|
Response
mixed
addColumn
Adds a column to an array of arrays or objects
addColumn(array array, array column, string colName, string keyCol = null) : array
since |
1.5.0 |
---|---|
see |
https://www.php.net/manual/en/language.types.array.php |
Arguments
- array
array
The source array- column
array
The array to be used as new column- colName
string
The index of the new column or name of the new object property- keyCol
string
The index of the column or name of object property to be used for mapping with the new column
Response
array
An array with the new column added to the source array
arrayFromObject
Utility function to map an object or array to an array
arrayFromObject(mixed item, bool recurse, string regex) : array
since |
1.0 |
---|
Arguments
- item
mixed
The source object or array- recurse
bool
True to recurse through multi-level objects- regex
string
An optional regular expression to match on field names
Response
array
arraySearch
An improved array_search that allows for partial matching of strings values in associative arrays.
arraySearch(string needle, array haystack, bool caseSensitive = true) : mixed
since |
1.0 |
---|
Arguments
- needle
string
The text to search for within the array.- haystack
array
Associative array to search in to find $needle.- caseSensitive
bool
True to search case sensitive, false otherwise.
Response
mixed
Returns the matching array $key if found, otherwise false.
arrayUnique
Multidimensional array safe unique test
arrayUnique(array array) : array
see |
https://www.php.net/manual/en/function.array-unique.php |
---|---|
since |
1.0 |
Arguments
- array
array
The array to make unique.
Response
array
dropColumn
Remove a column from an array of arrays or objects
dropColumn(array array, string colName) : array
since |
1.5.0 |
---|---|
see |
https://www.php.net/manual/en/language.types.array.php |
Arguments
- array
array
The source array- colName
string
The index of the column or name of object property to be removed
Response
array
Column of values from the source array
flatten
Method to recursively convert data to a one dimension array.
flatten(array|object array, string separator = '.', string prefix = '') : array
since |
1.3.0 |
---|
Arguments
- array
array|object
The array or object to convert.- separator
string
The key separator.- prefix
string
Last level key prefix.
Response
array
fromObject
Utility function to map an object to an array
fromObject(object source, bool recurse = true, string regex = null) : array
since |
1.0 |
---|
Arguments
- source
object
The source object- recurse
bool
True to recurse through multi-level objects- regex
string
An optional regular expression to match on field names
Response
array
getColumn
Extracts a column from an array of arrays or objects
getColumn(array array, string valueCol, string keyCol = null) : array
since |
1.0 |
---|---|
see |
https://www.php.net/manual/en/language.types.array.php https://www.php.net/manual/en/function.array-column.php |
Arguments
- array
array
The source array- valueCol
string
The index of the column or name of object property to be used as value It may also be NULL to return complete arrays or objects (this is useful together with $keyCol to reindex the array).- keyCol
string
The index of the column or name of object property to be used as key
Response
array
Column of values from the source array
getValue
Utility function to return a value from a named array or a specified default
getValue(array|\ArrayAccess array, string name, mixed default = null, string type = '') : mixed
since |
1.0 |
---|---|
throws |
|
Arguments
- array
array|\ArrayAccess
A named array or object that implements ArrayAccess- name
string
The key to search for (this can be an array index or a dot separated key sequence as in Registry)- default
mixed
The default value to give if no key found- type
string
Return type for the variable (INT, FLOAT, STRING, WORD, BOOLEAN, ARRAY)
Response
mixed
invert
Takes an associative array of arrays and inverts the array keys to values using the array values as keys.
invert(array array) : array
Example: $input = array( 'New' => array('1000', '1500', '1750'), 'Used' => array('3000', '4000', '5000', '6000') ); $output = ArrayHelper::invert($input);
Output would be equal to: $output = array( '1000' => 'New', '1500' => 'New', '1750' => 'New', '3000' => 'Used', '4000' => 'Used', '5000' => 'Used', '6000' => 'Used' );
since |
1.0 |
---|
Arguments
- array
array
The source array.
Response
array
isAssociative
Method to determine if an array is an associative array.
isAssociative(array array) : bool
since |
1.0 |
---|
Arguments
- array
array
An array to test.
Response
bool
mergeRecursive
Merge array recursively.
mergeRecursive(array args) : array
since |
2.0.0 |
---|---|
throws |
|
Arguments
- args
array
Array list to be merged.
Response
array
Merged array.
pivot
Pivots an array to create a reverse lookup of an array of scalars, arrays or objects.
pivot(array source, string key = null) : array
since |
1.0 |
---|
Arguments
- source
array
The source array.- key
string
Where the elements of the source array are objects or arrays, the key to pivot on.
Response
array
An array of arrays pivoted either on the value of the keys, or an individual key of an object or array.
sortObjects
Utility function to sort an array of objects on a given field
sortObjects(array a, mixed k, mixed direction = 1, mixed caseSensitive = true, mixed locale = false) : array
since |
1.0 |
---|
Arguments
- a
array
An array of objects- k
mixed
The key (string) or an array of keys to sort on- direction
mixed
Direction (integer) or an array of direction to sort in [1 = Ascending] [-1 = Descending]- caseSensitive
mixed
Boolean or array of booleans to let sort occur case sensitive or insensitive- locale
mixed
Boolean or array of booleans to let sort occur using the locale language or not
Response
array
toInteger
Function to convert array to integer values
toInteger(array array, int|array default = null) : array
since |
1.0 |
---|
Arguments
- array
array
The source array to convert- default
int|array
A default value to assign if $array is not an array
Response
array
toObject
Utility function to map an array to a stdClass object.
toObject(array array, string class = 'stdClass', bool recursive = true) : object
since |
1.0 |
---|
Arguments
- array
array
The array to map.- class
string
Name of the class to create- recursive
bool
Convert also any array inside the main array
Response
object
toString
Utility function to map an array to a string.
toString(array array, string innerGlue = '=', string outerGlue = ' ', bool keepOuterKey = false) : string
since |
1.0 |
---|
Arguments
- array
array
The array to map.- innerGlue
string
The glue (optional, defaults to '=') between the key and the value.- outerGlue
string
The glue (optional, defaults to ' ') between array elements.- keepOuterKey
bool
True if final key should be kept.
Response
string