FileAccess Orion

ArrayUtils
in package

Utility class for testing and manipulation of PHP arrays.

Declared abstract, as we have no need for instantiation.

Table of Contents

ARRAY_FILTER_USE_BOTH  = 1
Compatibility Flag for ArrayUtils::filter
ARRAY_FILTER_USE_KEY  = 2
Compatibility Flag for ArrayUtils::filter
filter()  : array<string|int, mixed>
hasIntegerKeys()  : bool
Test whether an array contains one or more integer keys
hasNumericKeys()  : bool
Test whether an array contains one or more numeric keys.
hasStringKeys()  : bool
Test whether an array contains one or more string keys
inArray()  : bool
Checks if a value exists in an array.
isHashTable()  : bool
Test whether an array is a hash table.
isList()  : bool
Test whether an array is a list
iteratorToArray()  : array<string|int, mixed>
Convert an iterator to an array.
merge()  : array<string|int, mixed>
Merge two arrays together.

Constants

ARRAY_FILTER_USE_BOTH

Compatibility Flag for ArrayUtils::filter

public mixed ARRAY_FILTER_USE_BOTH = 1

ARRAY_FILTER_USE_KEY

Compatibility Flag for ArrayUtils::filter

public mixed ARRAY_FILTER_USE_KEY = 2

Methods

filter()

public static filter(array<string|int, mixed> $data, callable $callback[, null|int $flag = null ]) : array<string|int, mixed>
Parameters
$data : array<string|int, mixed>
$callback : callable
$flag : null|int = null
Tags
deprecated

Since 3.2.0; use the native array_filter methods

throws
InvalidArgumentException
Return values
array<string|int, mixed>

hasIntegerKeys()

Test whether an array contains one or more integer keys

public static hasIntegerKeys(mixed $value[, bool $allowEmpty = false ]) : bool
Parameters
$value : mixed
$allowEmpty : bool = false

Should an empty array() return true

Return values
bool

hasNumericKeys()

Test whether an array contains one or more numeric keys.

public static hasNumericKeys(mixed $value[, bool $allowEmpty = false ]) : bool

A numeric key can be one of the following:

  • an integer 1,
  • a string with a number '20'
  • a string with negative number: '-1000'
  • a float: 2.2120, -78.150999
  • a string with float: '4000.99999', '-10.10'
Parameters
$value : mixed
$allowEmpty : bool = false

Should an empty array() return true

Return values
bool

hasStringKeys()

Test whether an array contains one or more string keys

public static hasStringKeys(mixed $value[, bool $allowEmpty = false ]) : bool
Parameters
$value : mixed
$allowEmpty : bool = false

Should an empty array() return true

Return values
bool

inArray()

Checks if a value exists in an array.

public static inArray(mixed $needle, array<string|int, mixed> $haystack[, int|bool $strict = false ]) : bool

Due to "foo" == 0 === TRUE with in_array when strict = false, an option has been added to prevent this. When $strict = 0/false, the most secure non-strict check is implemented. if $strict = -1, the default in_array non-strict behaviour is used.

Parameters
$needle : mixed
$haystack : array<string|int, mixed>
$strict : int|bool = false
Return values
bool

isHashTable()

Test whether an array is a hash table.

public static isHashTable(mixed $value[, bool $allowEmpty = false ]) : bool

An array is a hash table if:

  1. Contains one or more non-integer keys, or
  2. Integer keys are non-continuous or misaligned (not starting with 0)

For example: $hash = array( 'foo' => 15, 'bar' => false, ); $hash = array( 1995 => 'Birth of PHP', 2009 => 'PHP 5.3.0', 2012 => 'PHP 5.4.0', ); $hash = array( 'formElement, 'options' => array( 'debug' => true ), );

Parameters
$value : mixed
$allowEmpty : bool = false

Is an empty array() a valid hash table?

Return values
bool

isList()

Test whether an array is a list

public static isList(mixed $value[, bool $allowEmpty = false ]) : bool

A list is a collection of values assigned to continuous integer keys starting at 0 and ending at count() - 1.

For example: $list = array('a', 'b', 'c', 'd'); $list = array( 0 => 'foo', 1 => 'bar', 2 => array('foo' => 'baz'), );

Parameters
$value : mixed
$allowEmpty : bool = false

Is an empty list a valid list?

Return values
bool

iteratorToArray()

Convert an iterator to an array.

public static iteratorToArray(array<string|int, mixed>|Traversable $iterator[, bool $recursive = true ]) : array<string|int, mixed>

Converts an iterator to an array. The $recursive flag, on by default, hints whether or not you want to do so recursively.

Parameters
$iterator : array<string|int, mixed>|Traversable

The array or Traversable object to convert

$recursive : bool = true

Recursively check all nested structures

Tags
throws
InvalidArgumentException

if $iterator is not an array or a Traversable object

Return values
array<string|int, mixed>

merge()

Merge two arrays together.

public static merge(array<string|int, mixed> $a, array<string|int, mixed> $b[, bool $preserveNumericKeys = false ]) : array<string|int, mixed>

If an integer key exists in both arrays and preserveNumericKeys is false, the value from the second array will be appended to the first array. If both values are arrays, they are merged together, else the value of the second array overwrites the one of the first array.

Parameters
$a : array<string|int, mixed>
$b : array<string|int, mixed>
$preserveNumericKeys : bool = false
Return values
array<string|int, mixed>

Search results