public static
array
|
#
toInteger( array $array, mixed $default = null )
Function to convert array to integer values
Function to convert array to integer values
Parameters
- $array
array - $array The source array to convert
- $default
mixed - $default A default value (int|array) to assign if $array is not an array
Returns
array
Since
1.0
|
public static
object
|
#
toObject( array $array, string $class = 'stdClass', boolean $recursive = true )
Utility function to map an array to a stdClass object.
Utility function to map an array to a stdClass object.
Parameters
- $array
array - $array The array to map.
- $class
string - $class Name of the class to create
- $recursive
boolean - $recursive Convert also any array inside the main array
Returns
object
Since
1.0
|
public static
string
|
#
toString( array $array, string $inner_glue = '=', string $outer_glue = ' ', boolean $keepOuterKey = false )
Utility function to map an array to a string.
Utility function to map an array to a string.
Parameters
- $array
array - $array The array to map.
- $inner_glue
string - $inner_glue The glue (optional, defaults to '=') between the key and the value.
- $outer_glue
string - $outer_glue The glue (optional, defaults to ' ') between array elements.
- $keepOuterKey
boolean - $keepOuterKey True if final key should be kept.
Returns
string
Since
1.0
|
public static
array
|
#
fromObject( object $p_obj, boolean $recurse = true, string $regex = null )
Utility function to map an object to an array
Utility function to map an object to an array
Parameters
- $p_obj
object - $p_obj The source object
- $recurse
boolean - $recurse True to recurse through multi-level objects
- $regex
string - $regex An optional regular expression to match on field names
Returns
array
Since
1.0
|
public static
array
|
#
getColumn( array $array, string $valueCol, string $keyCol = null )
Extracts a column from an array of arrays or objects
Extracts a column from an array of arrays or objects
Parameters
- $array
array - $array The source array
- $valueCol
string - $valueCol The index of the column or name of object property to be used as value
It may also be NULL to return complete arrays or objects (this is useful
together with $keyCol to reindex the array).
- $keyCol
string - $keyCol The index of the column or name of object property to be used as key
Returns
array - Column of values from the source array
Since
1.0
See
|
public static
mixed
|
#
getValue( array|ArrayAccess $array, string $name, mixed $default = null, string $type = '' )
Utility function to return a value from a named array or a specified
default
Utility function to return a value from a named array or a specified
default
Parameters
- $array
array|ArrayAccess - $array A named array or object that implements ArrayAccess
- $name
string - $name The key to search for
- $default
mixed - $default The default value to give if no key found
- $type
string - $type Return type for the variable (INT, FLOAT, STRING, WORD, BOOLEAN, ARRAY)
Returns
mixed
Throws
Since
1.0
|
public static
array
|
#
invert( array $array )
Takes an associative array of arrays and inverts the array keys to values
using the array values as keys.
Takes an associative array of arrays and inverts the array keys to values
using the array values as keys.
Example: $input = array( 'New' => array('1000', '1500', '1750'), 'Used'
=> array('3000', '4000', '5000', '6000') ); $output =
ArrayHelper::invert($input);
Output would be equal to: $output = array( '1000' => 'New', '1500' =>
'New', '1750' => 'New', '3000' => 'Used', '4000' => 'Used', '5000'
=> 'Used', '6000' => 'Used' );
Parameters
- $array
array - $array The source array.
Returns
array
Since
1.0
|
public static
boolean
|
#
isAssociative( array $array )
Method to determine if an array is an associative array.
Method to determine if an array is an associative array.
Parameters
- $array
array - $array An array to test.
Returns
boolean
Since
1.0
|
public static
array
|
#
pivot( array $source, string $key = null )
Pivots an array to create a reverse lookup of an array of scalars, arrays or
objects.
Pivots an array to create a reverse lookup of an array of scalars, arrays or
objects.
Parameters
- $source
array - $source The source array.
- $key
string - $key Where the elements of the source array are objects or arrays, the key to
pivot on.
Returns
array - An array of arrays pivoted either on the value of the keys, or an individual key
of an object or array.
Since
1.0
|
public static
array
|
#
sortObjects( array $a, mixed $k, mixed $direction = 1, mixed $caseSensitive = true, mixed $locale = false )
Utility function to sort an array of objects on a given field
Utility function to sort an array of objects on a given field
Parameters
- $a
array - $a An array of objects
- $k
mixed - $k The key (string) or an array of keys to sort on
- $direction
mixed - $direction Direction (integer) or an array of direction to sort in [1 =
Ascending] [-1 = Descending]
- $caseSensitive
mixed - $caseSensitive Boolean or array of booleans to let sort occur case sensitive or
insensitive
- $locale
mixed - $locale Boolean or array of booleans to let sort occur using the locale language
or not
Returns
array
Since
1.0
|
public static
array
|
#
arrayUnique( array $array )
Multidimensional array safe unique test
Multidimensional array safe unique test
Parameters
- $array
array - $array The array to make unique.
Returns
array
Since
1.0
See
|
public static
mixed
|
#
arraySearch( string $needle, array $haystack, boolean $caseSensitive = true )
An improved array_search that allows for partial matching of strings values
in associative arrays.
An improved array_search that allows for partial matching of strings values
in associative arrays.
Parameters
- $needle
string - $needle The text to search for within the array.
- $haystack
array - $haystack Associative array to search in to find $needle.
- $caseSensitive
boolean - $caseSensitive True to search case sensitive, false otherwise.
Returns
mixed - Returns the matching array $key if found, otherwise false.
Since
1.0
|
public static
array
|
#
flatten( array|object $array, string $separator = '.', string $prefix = '' )
Method to recursively convert data to a one dimension array.
Method to recursively convert data to a one dimension array.
Parameters
- $array
array|object - $array The array or object to convert.
- $separator
string - $separator The key separator.
- $prefix
string - $prefix Last level key prefix.
Returns
array
Since
1.3.0
|