JArrayHelper

JArrayHelper is an array utility class for doing all sorts of odds and ends with arrays.

abstract deprecated
since

11.1

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
static
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
static
see \JArrayHelper::sortObjects()
since

11.1

Arguments

$a

$b

Response

integerComparison status

arrayUnique

Multidimensional array safe unique test

arrayUnique(array $myArray) : array
static deprecated
link

https://secure.php.net/manual/en/function.array-unique.php

since

11.2

deprecated

4.0 Use Joomla\Utilities\ArrayHelper::arrayUnique instead

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
static deprecated
since

11.1

deprecated

4.0 Use Joomla\Utilities\ArrayHelper::fromObject instead

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
static deprecated
since

11.1

deprecated

4.0 Use Joomla\Utilities\ArrayHelper::getColumn instead

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
static deprecated
since

11.1

deprecated

4.0 Use Joomla\Utilities\ArrayHelper::getValue instead

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

invert

Takes an associative array of arrays and inverts the array keys to values using the array values as keys.

invert(array $array) : array
static deprecated

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

12.3

deprecated

4.0 Use Joomla\Utilities\ArrayHelper::invert instead

Arguments

$array

arrayThe source array.

Response

arrayThe inverted array.

isAssociative

Method to determine if an array is an associative array.

isAssociative(array $array) : boolean
static deprecated
since

11.1

deprecated

4.0 Use Joomla\Utilities\ArrayHelper::isAssociative instead

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
static deprecated
since

11.3

deprecated

4.0 Use Joomla\Utilities\ArrayHelper::pivot instead

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
static deprecated
since

11.1

deprecated

4.0 Use Joomla\Utilities\ArrayHelper::sortObjects instead

Arguments

$a

$k

mixedThe key (string) or an array of keys 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
static deprecated
since

11.1

deprecated

4.0 Use Joomla\Utilities\ArrayHelper::toInteger instead

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', boolean $recursive = true) : object
static deprecated
since

11.1

deprecated

4.0 Use Joomla\Utilities\ArrayHelper::toObject instead

Arguments

$array

$class

stringName of the class to create

$recursive

booleanConvert also any array inside the main array

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
static deprecated
since

11.1

deprecated

4.0 Use Joomla\Utilities\ArrayHelper::toString instead

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.

static

Type(s)

mixed

sortDirection

Option to set the sort direction.

static

Type(s)

mixed

sortKey

Option to set the object key to sort on.

static

Type(s)

string

sortLocale

Option to perform a language aware sort.

static

Type(s)

mixed