PHP Class JBZoo\Utils\Arr

Afficher le fichier Open project: jbzoo/utils Class Usage Examples

Méthodes publiques

Méthode Description
addEachKey ( array $array, string $prefix ) : array Add some prefix to each key
clean ( array $haystack ) : array Clean array by custom rule
cleanBeforeJson ( array $array ) : array Clean array before serialize to JSON
first ( array $array ) : mixed Returns the first element in an array.
firstKey ( array $array ) : integer | string Returns the first key in an array.
flat ( array $array, boolean $preserve_keys = true ) : array Flatten a multi-dimensional array into a one dimensional array.
getField ( array $arrayList, string $fieldName = 'id' ) : array Get one field from array of arrays (array of objects)
groupByKey ( array $arrayList, string $key = 'id' ) : array Group array by key
implode ( string $glue, array $array ) : string
in ( string $value, array $array, boolean $returnKey = false ) : mixed Check is value exists in the array
isAssoc ( $array ) : boolean Check is array is type assoc
key ( string $key, mixed $array, boolean $returnValue = false ) : mixed Check is key exists
last ( array $array ) : mixed Returns the last element in an array.
lastKey ( array $array ) : integer | string Returns the last key in an array.
map ( Closure $function, array $array ) : array Recursive array mapping
mapDeep ( array $array, string $callback, boolean $onNoScalar = false ) : array Returns an array containing all the elements of arr1 after applying the callback function to each one.
search ( array $array, mixed $search, boolean $field = false ) : boolean | mixed Searches for a given value in an array of arrays, objects and scalar values. You can optionally specify a field of the nested arrays and objects to search in.
sortByArray ( array $array, array $orderArray ) : array Sort an array by keys based on another array
toComment ( array $data ) : string Convert assoc array to comment style
unique ( array $array, boolean $keepKeys = false ) : array Remove the duplicates from an array.
unshiftAssoc ( array &$array, string $key, mixed $value ) : array Add cell to the start of assoc array
wrap ( mixed $object ) : array Wraps its argument in an array unless it is already an array

Method Details

addEachKey() public static méthode

Add some prefix to each key
public static addEachKey ( array $array, string $prefix ) : array
$array array
$prefix string
Résultat array

clean() public static méthode

Clean array by custom rule
public static clean ( array $haystack ) : array
$haystack array
Résultat array

cleanBeforeJson() public static méthode

Clean array before serialize to JSON
public static cleanBeforeJson ( array $array ) : array
$array array
Résultat array

first() public static méthode

Returns the first element in an array.
public static first ( array $array ) : mixed
$array array
Résultat mixed

firstKey() public static méthode

Returns the first key in an array.
public static firstKey ( array $array ) : integer | string
$array array
Résultat integer | string

flat() public static méthode

Flatten a multi-dimensional array into a one dimensional array.
public static flat ( array $array, boolean $preserve_keys = true ) : array
$array array The array to flatten
$preserve_keys boolean Whether or not to preserve array keys. Keys from deeply nested arrays will overwrite keys from shallowy nested arrays
Résultat array

getField() public static méthode

Get one field from array of arrays (array of objects)
public static getField ( array $arrayList, string $fieldName = 'id' ) : array
$arrayList array
$fieldName string
Résultat array

groupByKey() public static méthode

Group array by key
public static groupByKey ( array $arrayList, string $key = 'id' ) : array
$arrayList array
$key string
Résultat array

implode() public static méthode

public static implode ( string $glue, array $array ) : string
$glue string
$array array
Résultat string

in() public static méthode

Check is value exists in the array
public static in ( string $value, array $array, boolean $returnKey = false ) : mixed
$value string
$array array
$returnKey boolean
Résultat mixed

isAssoc() public static méthode

Check is array is type assoc
public static isAssoc ( $array ) : boolean
$array
Résultat boolean

key() public static méthode

Check is key exists
public static key ( string $key, mixed $array, boolean $returnValue = false ) : mixed
$key string
$array mixed
$returnValue boolean
Résultat mixed

last() public static méthode

Returns the last element in an array.
public static last ( array $array ) : mixed
$array array
Résultat mixed

lastKey() public static méthode

Returns the last key in an array.
public static lastKey ( array $array ) : integer | string
$array array
Résultat integer | string

map() public static méthode

Recursive array mapping
public static map ( Closure $function, array $array ) : array
$function Closure
$array array
Résultat array

mapDeep() public static méthode

Returns an array containing all the elements of arr1 after applying the callback function to each one.
public static mapDeep ( array $array, string $callback, boolean $onNoScalar = false ) : array
$array array An array to run through the callback function
$callback string Callback function to run for each element in each array
$onNoScalar boolean Whether or not to call the callback function on nonscalar values (Objects, resources, etc)
Résultat array

sortByArray() public static méthode

Sort an array by keys based on another array
public static sortByArray ( array $array, array $orderArray ) : array
$array array
$orderArray array
Résultat array

toComment() public static méthode

Convert assoc array to comment style
public static toComment ( array $data ) : string
$data array
Résultat string

unique() public static méthode

Remove the duplicates from an array.
public static unique ( array $array, boolean $keepKeys = false ) : array
$array array
$keepKeys boolean
Résultat array

unshiftAssoc() public static méthode

Add cell to the start of assoc array
public static unshiftAssoc ( array &$array, string $key, mixed $value ) : array
$array array
$key string
$value mixed
Résultat array

wrap() public static méthode

Wraps its argument in an array unless it is already an array
public static wrap ( mixed $object ) : array
$object mixed
Résultat array