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
mixed
The source object or array- $recurse
boolean
True to recurse through multi-level objects- $regex
string
An optional regular expression to match on field names
Response
array
The 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
array
The 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
object
The source object- $recurse
boolean
True to recurse through multi-level objects- $regex
string
An optional regular expression to match on field names
Response
array
The 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
string
The index of the column or name of object property
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, string $name, mixed $default = null, string $type = '') : mixed
since |
11.1 |
---|
Arguments
- $array
- $name
string
The key to search for- $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
The 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
array
An array to test.
Response
boolean
True 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
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( &$a, mixed $k, mixed $direction = 1, mixed $caseSensitive = true, mixed $locale = false) : array
since |
11.1 |
---|
Arguments
- $a
- $k
mixed
The key (string) or a array of key 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
The sorted array of objects
toInteger
Function to convert array to integer values
toInteger( &$array, mixed $default = null) : void
since |
11.1 |
---|
Arguments
- $array
- $default
mixed
A 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
string
Name of the class to create
Response
object
The 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
array
The array to map.- $inner_glue
string
The glue (optional, defaults to '=') between the key and the value.- $outer_glue
string
The glue (optional, defaults to ' ') between array elements.- $keepOuterKey
boolean
True if final key should be kept.
Response
string
The 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