category OSS
package OSS_Array
copyright Copyright (c) 2007 - 2012, Open Source Solutions Limited, Dublin, Ireland
license New BSD License

 Methods

Callback function for changeValues()

cavCallback(mixed $item, mixed $key, array $params) : void
Static

Parameters

$item

mixed

/p>

$key

mixed

¶m array $params

$params

Changes values in an array.

changeValues(array $array, array $fromToArray) : void
Static

Handles nested arrays.

Parameters

$array

array

&$array

$fromToArray

array

array('from1' => 'to1', 'from2' => 'to2', 'from3' => 'to3', ...)

Takes a nested array - typically a result set from a query - and filters out a specific field from it.

filterField(array $array, string $fieldName, boolean $unique, boolean $removeNull) : array
Static

It does not preserve the array keys.

Parameters

$array

array

the input array

$fieldName

string

the field to filter out

$unique

boolean

default true it can filter out multiple occurences of the same value

$removeNull

boolean

default false if true then removes null values from the result set

Returns

array

Filters out key-value pairs from nested arrays, typically from Doctrine result sets.

filterKeyValuePairs(array $array, string $key, string $value, boolean $unique) : array
Static

Both the $pKey and $pValue parameters are array keys in the $pArray.

Parameters

$array

array

the input array

$key

string

key filtering

$value

string

value filtering

$unique

boolean

default true return with unique values only or not

Returns

array

Returns with an one-dimensional array of values from any kind of nested array.

flatten(array $array) : array
Static

Try to avoid recursive arrays to not to go into an infinite loop.

Returns with the values in an associative array by keeping the original key => value pairs. As it keeps the original keys, if a key exists more than once in the structure, it will be overwritten and will appear in the result only once, having the value of the last key-value pair.

Parameters

$array

array

The array to flatten

Returns

array

Recursively converts an object into an array.

objectToArray(object $object) : array
Static

Empty objects become empty arrays.

Parameters

$object

object

Returns

array

Removes array elements where the value is empty().

removeEmptyElements(array $array, boolean $keepKeys) : array
Static

Parameters

$array

array

The array to clean

$keepKeys

boolean

default true keep the original keys or assign new (numeric) ones

Returns

array

Removes entries from an array based on the matches of the passed regular expression.

removeFields(array $array, string $pattern) : array
Static

It handles multi-dimensional arrays.

Parameters

$array

array

the input array

$pattern

string

pattern for filter

Returns

array

Works exactly like shuffle(), but this works on associative arrays, too.

shuffleAssoc(array $array) : boolean

Parameters

$array

array

the array to shuffle, reference-type parameter, it contains the result, too

Returns

boolean

Represents an array as a HTML table and returns with it as a string.

toHtmlTable(array $pArray, string $pTitle, string $pWidth, string $pHeaderBgColour, string $pBorderColour) : string
Static

It handles multi-dimensional arrays, those are represented as nested tables. If $pArray is not an array or an empty array, then it returns with an empty string.

Parameters

$pArray

array

$pTitle

string

default '' the name of the variable or any other string, it will appear as a heading

$pWidth

string

default '' a valid CSS width, like '100px', '10%', '13em', etc.

$pHeaderBgColour

string

default '#404040'

$pBorderColour

string

default '#404040'

Returns

string