PHP 클래스 JBZoo\Utils\Arr

파일 보기 프로젝트 열기: jbzoo/utils 1 사용 예제들

공개 메소드들

메소드 설명
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

메소드 상세

addEachKey() 공개 정적인 메소드

Add some prefix to each key
public static addEachKey ( array $array, string $prefix ) : array
$array array
$prefix string
리턴 array

clean() 공개 정적인 메소드

Clean array by custom rule
public static clean ( array $haystack ) : array
$haystack array
리턴 array

cleanBeforeJson() 공개 정적인 메소드

Clean array before serialize to JSON
public static cleanBeforeJson ( array $array ) : array
$array array
리턴 array

first() 공개 정적인 메소드

Returns the first element in an array.
public static first ( array $array ) : mixed
$array array
리턴 mixed

firstKey() 공개 정적인 메소드

Returns the first key in an array.
public static firstKey ( array $array ) : integer | string
$array array
리턴 integer | string

flat() 공개 정적인 메소드

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
리턴 array

getField() 공개 정적인 메소드

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

groupByKey() 공개 정적인 메소드

Group array by key
public static groupByKey ( array $arrayList, string $key = 'id' ) : array
$arrayList array
$key string
리턴 array

implode() 공개 정적인 메소드

public static implode ( string $glue, array $array ) : string
$glue string
$array array
리턴 string

in() 공개 정적인 메소드

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

isAssoc() 공개 정적인 메소드

Check is array is type assoc
public static isAssoc ( $array ) : boolean
$array
리턴 boolean

key() 공개 정적인 메소드

Check is key exists
public static key ( string $key, mixed $array, boolean $returnValue = false ) : mixed
$key string
$array mixed
$returnValue boolean
리턴 mixed

last() 공개 정적인 메소드

Returns the last element in an array.
public static last ( array $array ) : mixed
$array array
리턴 mixed

lastKey() 공개 정적인 메소드

Returns the last key in an array.
public static lastKey ( array $array ) : integer | string
$array array
리턴 integer | string

map() 공개 정적인 메소드

Recursive array mapping
public static map ( Closure $function, array $array ) : array
$function Closure
$array array
리턴 array

mapDeep() 공개 정적인 메소드

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)
리턴 array

sortByArray() 공개 정적인 메소드

Sort an array by keys based on another array
public static sortByArray ( array $array, array $orderArray ) : array
$array array
$orderArray array
리턴 array

toComment() 공개 정적인 메소드

Convert assoc array to comment style
public static toComment ( array $data ) : string
$data array
리턴 string

unique() 공개 정적인 메소드

Remove the duplicates from an array.
public static unique ( array $array, boolean $keepKeys = false ) : array
$array array
$keepKeys boolean
리턴 array

unshiftAssoc() 공개 정적인 메소드

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

wrap() 공개 정적인 메소드

Wraps its argument in an array unless it is already an array
public static wrap ( mixed $object ) : array
$object mixed
리턴 array