Utility class for testing and manipulation of PHP arrays.

Declared abstract, as we have no need for instantiation.

category Zend
package Zend_Stdlib

 Methods

Test whether an array contains one or more integer keys

hasIntegerKeys(mixed $value, bool $allowEmpty) : bool

Parameters

$value

mixed

$allowEmpty

bool

Should an empty array() return true

Returns

bool

Test whether an array contains one or more numeric keys.

hasNumericKeys(mixed $value, bool $allowEmpty) : 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

Should an empty array() return true

Returns

bool

Test whether an array contains one or more string keys

hasStringKeys(mixed $value, bool $allowEmpty) : bool

Parameters

$value

mixed

$allowEmpty

bool

Should an empty array() return true

Returns

bool

Test whether an array is a hash table.

isHashTable(mixed $value, bool $allowEmpty) : 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

Is an empty array() a valid hash table?

Returns

bool

Test whether an array is a list

isList(mixed $value, bool $allowEmpty) : 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

Is an empty list a valid list?

Returns

bool

Convert an iterator to an array.

iteratorToArray(array | \Traversable $iterator, bool $recursive) : array

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\Traversable

The array or Traversable object to convert

$recursive

bool

Recursively check all nested structures

Exceptions

\Zend\Stdlib\Exception\InvalidArgumentException if $iterator is not an array or a Traversable object

Returns

array

Merge two arrays together.

merge(array $a, array $b) : array

If an integer key exists in both arrays, the value from the second array will be appended the 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

$b

array

Returns

array