JArrayHelper
JArrayHelper is an array utility class for doing all sorts of odds and ends with arrays.
since |
1.7.0 |
---|---|
deprecated |
4.0 Use Joomla\Utilities\ArrayHelper instead |
package |
Joomla.Platform |
Methods
_fromObject
Utility function to map an object or array to an array
_fromObject(mixed $item, boolean $recurse, string $regex) : array
since |
1.7.0 |
---|
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(array $a, array $b) : integer
see | \JArrayHelper::sortObjects() |
---|---|
since |
1.7.0 |
Arguments
- $a
array
An array of objects- $b
array
An array of objects
Response
integer
Comparison status
arrayUnique
Multidimensional array safe unique test
arrayUnique(array $myArray) : array
link | |
---|---|
since |
1.7.0 |
deprecated |
4.0 Use Joomla\Utilities\ArrayHelper::arrayUnique instead |
Arguments
- $myArray
array
The array to make unique.
Response
array
fromObject
Utility function to map an object to an array
fromObject(object $object, boolean $recurse = true, string $regex = null) : array
since |
1.7.0 |
---|---|
deprecated |
4.0 Use Joomla\Utilities\ArrayHelper::fromObject instead |
Arguments
- $object
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 |
1.7.0 |
---|---|
deprecated |
4.0 Use Joomla\Utilities\ArrayHelper::getColumn instead |
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 |
1.7.0 |
---|---|
deprecated |
4.0 Use Joomla\Utilities\ArrayHelper::getValue instead |
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
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 = JArrayHelper::invert($input);
Output would be equal to: $output = array( '1000' => 'New', '1500' => 'New', '1750' => 'New', '3000' => 'Used', '4000' => 'Used', '5000' => 'Used', '6000' => 'Used' );
since |
3.1.4 |
---|---|
deprecated |
4.0 Use Joomla\Utilities\ArrayHelper::invert instead |
Arguments
- $array
array
The source array.
Response
array
The inverted array.
isAssociative
Method to determine if an array is an associative array.
isAssociative(array $array) : boolean
since |
1.7.0 |
---|---|
deprecated |
4.0 Use Joomla\Utilities\ArrayHelper::isAssociative instead |
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 |
1.7.3 |
---|---|
deprecated |
4.0 Use Joomla\Utilities\ArrayHelper::pivot instead |
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 |
1.7.0 |
---|---|
deprecated |
4.0 Use Joomla\Utilities\ArrayHelper::sortObjects instead |
Arguments
- $a
- $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
The sorted array of objects
toInteger
Function to convert array to integer values
toInteger( &$array, mixed $default = null) : void
since |
1.7.0 |
---|---|
deprecated |
4.0 Use Joomla\Utilities\ArrayHelper::toInteger instead |
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', boolean $recursive = true) : object
since |
1.7.0 |
---|---|
deprecated |
4.0 Use Joomla\Utilities\ArrayHelper::toObject instead |
Arguments
- $array
- $class
string
Name of the class to create- $recursive
boolean
Convert also any array inside the main array
Response
object
The object mapped from the given array
toString
Utility function to map an array to a string.
toString(array $array = null, string $innerGlue = '=', string $outerGlue = ' ', boolean $keepOuterKey = false) : string
since |
1.7.0 |
---|---|
deprecated |
4.0 Use Joomla\Utilities\ArrayHelper::toString instead |
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
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 |
1.7.3 |
---|
Type(s)
mixed
sortDirection
Option to set the sort direction.
since |
1.7.3 |
---|
Type(s)
mixed
sortKey
Option to set the object key to sort on.
since |
1.7.3 |
---|
Type(s)
string
sortLocale
Option to perform a language aware sort.
since |
1.7.3 |
---|
Type(s)
mixed