Zend Framework  3.0
Static Public Member Functions | Public Attributes | List of all members
ArrayUtils Class Reference

Utility class for testing and manipulation of PHP arrays. More...

Static Public Member Functions

static hasStringKeys ($value, $allowEmpty=false)
 Test whether an array contains one or more string keys.
 
static hasIntegerKeys ($value, $allowEmpty=false)
 Test whether an array contains one or more integer keys.
 
static hasNumericKeys ($value, $allowEmpty=false)
 Test whether an array contains one or more numeric keys.
 
static isList ($value, $allowEmpty=false)
 Test whether an array is a list.
 
static isHashTable ($value, $allowEmpty=false)
 Test whether an array is a hash table.
 
static inArray ($needle, array $haystack, $strict=false)
 Checks if a value exists in an array.
 
static iteratorToArray ($iterator, $recursive=true)
 Convert an iterator to an array.
 
static merge (array $a, array $b, $preserveNumericKeys=false)
 Merge two arrays together.
 
static filter (array $data, $callback, $flag=null)
 Compatibility Method for array_filter on <5.6 systems.
 

Public Attributes

const ARRAY_FILTER_USE_BOTH = 1
 Compatibility Flag for ArrayUtils::filter.
 
const ARRAY_FILTER_USE_KEY = 2
 Compatibility Flag for ArrayUtils::filter.
 

Detailed Description

Utility class for testing and manipulation of PHP arrays.

Declared abstract, as we have no need for instantiation.

Member Function Documentation

static filter ( array  $data,
  $callback,
  $flag = null 
)
static

Compatibility Method for array_filter on <5.6 systems.

Parameters
array$data
callable$callback
null | int$flag
Returns
array
static hasIntegerKeys (   $value,
  $allowEmpty = false 
)
static

Test whether an array contains one or more integer keys.

Parameters
mixed$value
bool$allowEmptyShould an empty array() return true
Returns
bool
static hasNumericKeys (   $value,
  $allowEmpty = false 
)
static

Test whether an array contains one or more numeric keys.

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
mixed$value
bool$allowEmptyShould an empty array() return true
Returns
bool
static hasStringKeys (   $value,
  $allowEmpty = false 
)
static

Test whether an array contains one or more string keys.

Parameters
mixed$value
bool$allowEmptyShould an empty array() return true
Returns
bool
static inArray (   $needle,
array  $haystack,
  $strict = false 
)
static

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.

Parameters
mixed$needle
array$haystack
int | bool$strict
Returns
bool
static isHashTable (   $value,
  $allowEmpty = false 
)
static

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

Parameters
mixed$value
bool$allowEmptyIs an empty array() a valid hash table?
Returns
bool
static isList (   $value,
  $allowEmpty = false 
)
static

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

Parameters
mixed$value
bool$allowEmptyIs an empty list a valid list?
Returns
bool
static iteratorToArray (   $iterator,
  $recursive = true 
)
static

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.

Parameters
array | Traversable$iteratorThe array or Traversable object to convert
bool$recursiveRecursively check all nested structures
Exceptions
Exception\InvalidArgumentExceptionif $iterator is not an array or a Traversable object
Returns
array
static merge ( array  $a,
array  $b,
  $preserveNumericKeys = false 
)
static

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.

Parameters
array$a
array$b
bool$preserveNumericKeys
Returns
array

Member Data Documentation

const ARRAY_FILTER_USE_BOTH = 1

Compatibility Flag for ArrayUtils::filter.

const ARRAY_FILTER_USE_KEY = 2

Compatibility Flag for ArrayUtils::filter.