PHP 트레잇 Webiny\Component\StdLib\StdObject\ArrayObject\ManipulatorTrait

파일 보기 프로젝트 열기: Webiny/Framework

공개 메소드들

메소드 설명
append ( mixed $k, mixed $v = null ) Inserts an element to the end of the array.
changeKeyCase ( string $case ) Change the case of all keys in current ArrayObject.
chunk ( integer $size, boolean $preserve_keys = false ) : ArrayObject Split an array into chunks.
diff ( $array, boolean $compareKeys = false ) : ArrayObject Compare two arrays or ArrayObjects and returns an ArrayObject containing all the values from current ArrayObject that are not present in any of the other array.
diffKeys ( $array ) : ArrayObject Compare the keys from two arrays or ArrayObjects and returns an ArrayObject containing all the values from current ArrayObject whose keys are not present in any of the other arrays.
fill ( integer $start, integer $num, mixed $value ) Fill array with values.
fillKeys ( mixed $value ) Use current array as keys and fill them with $value.
filter ( string $callable = '' ) Filter array values by using a callback function.
flip ( ) Exchanges all keys with their associated values in the array.
implode ( string $glue ) : StringObject Implode the array with the given $glue.
intersect ( $array ) Remove all elements from the current array that are not present in the given $array.
intersectAssoc ( array $array, string $callable = '' ) Remove all elements from the current array that are not present in the given $array.
intersectKey ( array $array, string $callable = '' ) Remove all elements from the current array that are not present in the given $array.
join ( string $glue ) : StringObject Implode the array with the given $glue.
key ( string | integer | StringObject $key, null | mixed $value = null, boolean $setOnlyIfDoesntExist = false ) Get or update the given key inside current array.
keyNested ( string | integer | StringObject $key, null | mixed $value = null, boolean $setOnlyIfDoesntExist = false ) Get or update the given key inside current array. This method supports nested key access: 'level1.level2.level3'
map ( string $callable ) Apply the $callback function to all elements of current array.
merge ( array | ArrayObject $array ) Merge given $array with current array.
mergeRecursive ( array | ArrayObject $array ) Merge given $array with current array recursively.
mergeSmart ( array | ArrayObject $array ) Merge given $array with current array using smart algorithm.
pad ( integer $size, mixed $value ) Pad array to the specified length with a value.
prepend ( mixed $k, mixed $v = null ) Inserts an element at the beginning of the array.
rand ( integer $num = 1 ) : ArrayObject Returns random elements from current array.
removeFirst ( null &$assign = null ) Removes the first element from the array.
removeKey ( string | array $key ) Remove the element(s) from the array under the given $key.
removeLast ( null &$assign = null ) Removes the last element from the array.
replace ( array | ArrayObject $replacements, boolean $recursive = false ) This method replaces the values of current array with the values from $array for the matching keys.
reverse ( ) Reverse the order of elements in the current array.
shuffle ( ) Shuffle elements in the array.
slice ( integer $offset, null | integer $length = null, boolean $preserveKeys = true ) Slice a portion of current array and discard the remains.
sort ( integer $direction = SORT_ASC, integer $sortFlag = SORT_REGULAR ) Sort the array by its values (does not maintain index association).
sortAssoc ( integer $direction = SORT_ASC, integer $sortFlag = SORT_REGULAR ) Sort the array by its values (maintains key association).
sortField ( string $field, integer $direction = SORT_ASC, integer $sortFlag = SORT_NUMERIC ) Sort an assoc array by a value inside the defined $field.
sortKey ( integer $direction = SORT_ASC, integer $sortFlag = SORT_REGULAR ) Sort the array by its key.
sortUsingFunction ( callable $comparisonFunction ) Sort an array by values using a user-defined comparison function
This function assigns new keys to the elements in array. It will remove any existing keys that may have been assigned, rather than just reordering the keys.
The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
splice ( integer $offset, integer $length, boolean $replacement ) Remove a portion of the array and replace it with something else.
unique ( integer $sortFlag = SORT_REGULAR ) Remove duplicates from the array.
walk ( mixed $callable, boolean $recursive = false, null $userData = null ) Applies the user-defined function to each element of the input array.

비공개 메소드들

메소드 설명
handleNestedValue ( string $key, mixed $value, boolean $setOnlyIfNotExists ) Set or get given $value for given $key.

메소드 상세

append() 공개 메소드

If you set both params, that first param is the key, and second is the value, else first param is the value, and the second is ignored.
public append ( mixed $k, mixed $v = null )
$k mixed
$v mixed

changeKeyCase() 공개 메소드

Change the case of all keys in current ArrayObject.
public changeKeyCase ( string $case )
$case string Case to which you want to covert array keys. Can be 'lower' or 'upper'.

chunk() 공개 메소드

Split an array into chunks.
public chunk ( integer $size, boolean $preserve_keys = false ) : ArrayObject
$size integer Chunk size.
$preserve_keys boolean Do you want ot preserve keys.
리턴 ArrayObject A new instance of ArrayObject containing a multidimensional numerically indexed array, starting with zero, with each dimension containing size elements.

diff() 공개 메소드

Compare two arrays or ArrayObjects and returns an ArrayObject containing all the values from current ArrayObject that are not present in any of the other array.
public diff ( $array, boolean $compareKeys = false ) : ArrayObject
$array Array to which to compare
$compareKeys boolean Do you want to compare array keys also. Default is false.
리턴 ArrayObject

diffKeys() 공개 메소드

Compare the keys from two arrays or ArrayObjects and returns an ArrayObject containing all the values from current ArrayObject whose keys are not present in any of the other arrays.
public diffKeys ( $array ) : ArrayObject
$array Array to which to compare
리턴 ArrayObject

fill() 공개 메소드

Number of items is defined by $num param, and start index is defined by $start param. If you have items in your current array, they will be removed.
public fill ( integer $start, integer $num, mixed $value )
$start integer The first index of the returned array.
$num integer Number of elements to insert. Must be greater than zero.
$value mixed Value to use for filling.

fillKeys() 공개 메소드

Use current array as keys and fill them with $value.
public fillKeys ( mixed $value )
$value mixed Value to use for filling.

filter() 공개 메소드

Filter array values by using a callback function.
public filter ( string $callable = '' )
$callable string

flip() 공개 메소드

Note: This function can only flip STRING and INTEGER values. Other types will throw a E_WARNING (no exceptions, sorry :( )
public flip ( )

implode() 공개 메소드

Implode the array with the given $glue.
public implode ( string $glue ) : StringObject
$glue string String that will be used to put elements together.
리턴 Webiny\Component\StdLib\StdObject\StringObject\StringObject Instance of StringObject containing the array elements glued together as a string.

intersect() 공개 메소드

Keys ARE NOT used in the comparison.
public intersect ( $array )
$array Array for comparison.

intersectAssoc() 공개 메소드

This function uses array keys for comparison unlike 'intersect' method.
public intersectAssoc ( array $array, string $callable = '' )
$array array Array for comparison
$callable string Optional callback function that can be uses for comparison.

intersectKey() 공개 메소드

This function compares ONLY array keys.
public intersectKey ( array $array, string $callable = '' )
$array array Array for comparison
$callable string Optional callback function that can be uses for comparison.

join() 공개 메소드

Implode the array with the given $glue.
public join ( string $glue ) : StringObject
$glue string String that will be used to put elements together.
리턴 Webiny\Component\StdLib\StdObject\StringObject\StringObject Instance of StringObject containing the array elements glued together as a string.

key() 공개 메소드

Get or update the given key inside current array.
public key ( string | integer | StringObject $key, null | mixed $value = null, boolean $setOnlyIfDoesntExist = false )
$key string | integer | Webiny\Component\StdLib\StdObject\StringObject\StringObject Array key
$value null | mixed If set, the value under current $key will be updated and not returned.
$setOnlyIfDoesntExist boolean Set the $value only in case if the $key doesn't exist.

keyNested() 공개 메소드

Get or update the given key inside current array. This method supports nested key access: 'level1.level2.level3'
public keyNested ( string | integer | StringObject $key, null | mixed $value = null, boolean $setOnlyIfDoesntExist = false )
$key string | integer | Webiny\Component\StdLib\StdObject\StringObject\StringObject Array key Eg: 'level1.level2.level3'
$value null | mixed If set, the value under current $key will be updated and not returned.
$setOnlyIfDoesntExist boolean Set the $value only in case if the $key doesn't exist.

map() 공개 메소드

Apply the $callback function to all elements of current array.
public map ( string $callable )
$callable string A callable function.

merge() 공개 메소드

Merge given $array with current array.
public merge ( array | ArrayObject $array )
$array array | ArrayObject

mergeRecursive() 공개 메소드

If two arrays contain same keys, their values wil be merged together
public mergeRecursive ( array | ArrayObject $array )
$array array | ArrayObject

mergeSmart() 공개 메소드

This will result in the most logical array: - simple values will be overwritten - numeric index arrays will be appended to the original array
(numeric indexes are not replacing the original array index, their values are simply appended to the original array) - associative arrays will be merged This method works exactly the same way as Config component mergeWith($config) method.
public mergeSmart ( array | ArrayObject $array )
$array array | ArrayObject

pad() 공개 메소드

Pad array to the specified length with a value.
public pad ( integer $size, mixed $value )
$size integer New size of the array
$value mixed Value to pad if array is smaller than pad_size.

prepend() 공개 메소드

If you set both params, that first param is the key, and second is the value, else first param is the value, and the second is ignored.
public prepend ( mixed $k, mixed $v = null )
$k mixed
$v mixed

rand() 공개 메소드

Returns random elements from current array.
public rand ( integer $num = 1 ) : ArrayObject
$num integer How many object you want to return.
리턴 ArrayObject

removeFirst() 공개 메소드

If $assign parameter is given, the removed value will be assigned to it.
public removeFirst ( null &$assign = null )
$assign null Assign removed value to given parameter

removeKey() 공개 메소드

Remove the element(s) from the array under the given $key.
public removeKey ( string | array $key )
$key string | array Key(s) that will be removed from the array.

removeLast() 공개 메소드

Removes the last element from the array.
public removeLast ( null &$assign = null )
$assign null Assign removed value to given parameter

replace() 공개 메소드

If a key from the current array exists in the $replacements array, its value will be replaced by the value from $replacements. If the key exists in $replacements, and not in the current array, it will be created in the current array. If a key only exists in the current array, it will be left as is. If $recursive is TRUE it will recurse into arrays and apply the same process to the inner value.
public replace ( array | ArrayObject $replacements, boolean $recursive = false )
$replacements array | ArrayObject
$recursive boolean

reverse() 공개 메소드

Reverse the order of elements in the current array.
public reverse ( )

shuffle() 공개 메소드

Shuffle elements in the array.
public shuffle ( )

slice() 공개 메소드

Slice a portion of current array and discard the remains.
public slice ( integer $offset, null | integer $length = null, boolean $preserveKeys = true )
$offset integer From where to start slicing.
$length null | integer How many elements to take.
$preserveKeys boolean Do you want to preserve the keys from the current array. Default is true.

sort() 공개 메소드

This sort function take two flags. One defines the sort algorithm, and the other one, the sort direction. Default behavior equals to the standard sort function.
public sort ( integer $direction = SORT_ASC, integer $sortFlag = SORT_REGULAR )
$direction integer In which direction you want to sort. You can use SORT_ASC or SORT_DESC.
$sortFlag integer Which sort algorithm. SORT_REGULAR | SORT_NUMERIC | SORT_STRING | SORT_LOCALE_STRING | SORT_NATURAL

sortAssoc() 공개 메소드

This sort function take two flags. One defines the sort algorithm, and the other one, the sort direction. Default behavior equals to the standard asort function.
public sortAssoc ( integer $direction = SORT_ASC, integer $sortFlag = SORT_REGULAR )
$direction integer In which direction you want to sort. You can use SORT_ASC or SORT_DESC.
$sortFlag integer Which sort algorithm. SORT_REGULAR | SORT_NUMERIC | SORT_STRING | SORT_LOCALE_STRING | SORT_NATURAL

sortField() 공개 메소드

Sort an assoc array by a value inside the defined $field.
public sortField ( string $field, integer $direction = SORT_ASC, integer $sortFlag = SORT_NUMERIC )
$field string
$direction integer
$sortFlag integer

sortKey() 공개 메소드

This sort function take two flags. One defines the sort algorithm, and the other one, the sort direction. Default behavior equals to the standard asort function.
public sortKey ( integer $direction = SORT_ASC, integer $sortFlag = SORT_REGULAR )
$direction integer In which direction you want to sort. You can use SORT_ASC or SORT_DESC.
$sortFlag integer Which sort algorithm. SORT_REGULAR | SORT_NUMERIC | SORT_STRING | SORT_LOCALE_STRING | SORT_NATURAL

sortUsingFunction() 공개 메소드

Sort an array by values using a user-defined comparison function
This function assigns new keys to the elements in array. It will remove any existing keys that may have been assigned, rather than just reordering the keys.
The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
public sortUsingFunction ( callable $comparisonFunction )
$comparisonFunction callable

splice() 공개 메소드

Remove a portion of the array and replace it with something else.
public splice ( integer $offset, integer $length, boolean $replacement )
$offset integer From where to start slicing.
$length integer How many elements to take.
$replacement boolean With what to replace the selected portion.

unique() 공개 메소드

Remove duplicates from the array.
public unique ( integer $sortFlag = SORT_REGULAR )
$sortFlag integer The optional parameter that may be used to modify the sorting behavior. Possible values are: SORT_STRING, SORT_NUMERIC, SORT_REGULAR and SORT_LOCALE_STRING

walk() 공개 메소드

If $recursive the function will recurse into deeper arrays.
public walk ( mixed $callable, boolean $recursive = false, null $userData = null )
$callable mixed Which function will be called for each array value.
$recursive boolean Go into deeper levels of the array. Default: false.
$userData null Optional data that can be passed along to the user callable $function.