JArrayHelper
JArrayHelper is an array utility class for doing all sorts of odds and ends with arrays.
| package |
Joomla.Platform |
|---|---|
| subpackage |
Utilities |
| since |
11.1 |
Methods
_fromObject
Utility function to map an object or array to an array
_fromObject(mixed $item, boolean $recurse, string $regex) : array
| since |
11.1 |
|---|
Arguments
- $item
mixedThe source object or array- $recurse
booleanTrue to recurse through multi-level objects- $regex
stringAn optional regular expression to match on field names
Response
arrayThe array mapped from the given object
_sortObjects
Callback function for sorting an array of objects on a key
_sortObjects( &$a, &$b) : integer
arrayUnique
Multidimensional array safe unique test
arrayUnique(array $myArray) : array
| see | |
|---|---|
| since |
11.2 |
Arguments
- $myArray
arrayThe array to make unique.
Response
array
fromObject
Utility function to map an object to an array
fromObject(object $p_obj, boolean $recurse = true, string $regex = null) : array
| since |
11.1 |
|---|
Arguments
- $p_obj
objectThe source object- $recurse
booleanTrue to recurse through multi-level objects- $regex
stringAn optional regular expression to match on field names
Response
arrayThe array mapped from the given object
getColumn
Extracts a column from an array of arrays or objects
getColumn( &$array, string $index) : array
| since |
11.1 |
|---|
Arguments
- $array
- $index
stringThe index of the column or name of object property
Response
arrayColumn of values from the source array
getValue
Utility function to return a value from a named array or a specified default
getValue( &$array, string $name, mixed $default = null, string $type = '') : mixed
| since |
11.1 |
|---|
Arguments
- $array
- $name
stringThe key to search for- $default
mixedThe default value to give if no key found- $type
stringReturn type for the variable (INT, FLOAT, STRING, WORD, BOOLEAN, ARRAY)
Response
mixedThe value from the source array
isAssociative
Method to determine if an array is an associative array.
isAssociative(array $array) : boolean
| since |
11.1 |
|---|
Arguments
- $array
arrayAn array to test.
Response
booleanTrue if the array is an associative 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 |
11.3 |
|---|
Arguments
- $source
arrayThe source array.- $key
stringWhere the elements of the source array are objects or arrays, the key to pivot on.
Response
arrayAn 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( &$a, mixed $k, mixed $direction = 1, mixed $caseSensitive = true, mixed $locale = false) : array
| since |
11.1 |
|---|
Arguments
- $a
- $k
mixedThe key (string) or a array of key to sort on- $direction
mixedDirection (integer) or an array of direction to sort in [1 = Ascending] [-1 = Descending]- $caseSensitive
mixedBoolean or array of booleans to let sort occur case sensitive or insensitive- $locale
mixedBoolean or array of booleans to let sort occur using the locale language or not
Response
arrayThe sorted array of objects
toInteger
Function to convert array to integer values
toInteger( &$array, mixed $default = null) : void
| since |
11.1 |
|---|
Arguments
- $array
- $default
mixedA default value (int|array) to assign if $array is not an array
toObject
Utility function to map an array to a stdClass object.
toObject( &$array, string $class = 'stdClass') : object
| since |
11.1 |
|---|
Arguments
- $array
- $class
stringName of the class to create
Response
objectThe object mapped from the given array
toString
Utility function to map an array to a string.
toString(array $array = null, string $inner_glue = '=', string $outer_glue = ' ', boolean $keepOuterKey = false) : string
| since |
11.1 |
|---|
Arguments
- $array
arrayThe array to map.- $inner_glue
stringThe glue (optional, defaults to '=') between the key and the value.- $outer_glue
stringThe glue (optional, defaults to ' ') between array elements.- $keepOuterKey
booleanTrue if final key should be kept.
Response
stringThe string mapped from the given array
Properties
sortCase
Option to perform case-sensitive sorts.
| since |
11.3 |
|---|
Type(s)
mixed
sortDirection
Option to set the sort direction.
| since |
11.3 |
|---|
Type(s)
mixed
sortKey
Option to set the object key to sort on.
| since |
11.3 |
|---|
Type(s)
string
sortLocale
Option to perform a language aware sort.
| since |
11.3 |
|---|
Type(s)
mixed