Class ArrayUtils

Summary

Fully Qualified Name: Zend\Stdlib\ArrayUtils

Description

Utility class for testing and manipulation of PHP arrays.

Declared abstract, as we have no need for instantiation.

Methods

Name Description Defined By
filter() ArrayUtils
hasIntegerKeys() Test whether an array contains one or more integer keys ArrayUtils
hasNumericKeys() Test whether an array contains one or more numeric keys. ArrayUtils
hasStringKeys() Test whether an array contains one or more string keys ArrayUtils
inArray() Checks if a value exists in an array. ArrayUtils
isHashTable() Test whether an array is a hash table. ArrayUtils
isList() Test whether an array is a list ArrayUtils
iteratorToArray() Convert an iterator to an array. ArrayUtils
merge() Merge two arrays together. ArrayUtils

Method Details

filter()

Parameter Name Type Description
$data array
$callback callable
$flag null|int

Returns: array

hasIntegerKeys()

Test whether an array contains one or more integer keys

Parameter Name Type Description
$value mixed
$allowEmpty bool Should

Returns: bool

hasNumericKeys()

Test whether an array contains one or more numeric keys.

A numeric key can be one of the following:

Parameter Name Type Description
$value mixed
$allowEmpty bool Should

Returns: bool

hasStringKeys()

Test whether an array contains one or more string keys

Parameter Name Type Description
$value mixed
$allowEmpty bool Should

Returns: bool

inArray()

Checks if a value exists in an array.

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.

Parameter Name Type Description
$needle mixed
$haystack array
$strict int|bool

Returns: bool

isHashTable()

Test whether an array is a hash table.

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 ),

);

Parameter Name Type Description
$value mixed
$allowEmpty bool Is

Returns: bool

isList()

Test whether an array is a list

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'),

);

Parameter Name Type Description
$value mixed
$allowEmpty bool Is

Returns: bool

iteratorToArray()

Convert an iterator to an array.

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

Parameter Name Type Description
$iterator array|\Traversable The
$recursive bool Recursively

Returns: array

merge()

Merge two arrays together.

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.

Parameter Name Type Description
$a array
$b array
$preserveNumericKeys bool

Returns: array

Top