PHP Trait Webiny\Component\StdLib\StdObject\ArrayObject\ManipulatorTrait

Afficher le fichier Open project: Webiny/Framework

Méthodes publiques

Méthode Description
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.

Private Methods

Méthode Description
handleNestedValue ( string $key, mixed $value, boolean $setOnlyIfNotExists ) Set or get given $value for given $key.

Method Details

append() public méthode

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() public méthode

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() public méthode

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.
Résultat ArrayObject A new instance of ArrayObject containing a multidimensional numerically indexed array, starting with zero, with each dimension containing size elements.

diff() public méthode

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.
Résultat ArrayObject

diffKeys() public méthode

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
Résultat ArrayObject

fill() public méthode

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() public méthode

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

filter() public méthode

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

flip() public méthode

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

implode() public méthode

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

intersect() public méthode

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

intersectAssoc() public méthode

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() public méthode

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() public méthode

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

key() public méthode

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() public méthode

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() public méthode

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

merge() public méthode

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

mergeRecursive() public méthode

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

mergeSmart() public méthode

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() public méthode

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() public méthode

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() public méthode

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

removeFirst() public méthode

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() public méthode

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() public méthode

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

replace() public méthode

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() public méthode

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

shuffle() public méthode

Shuffle elements in the array.
public shuffle ( )

slice() public méthode

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() public méthode

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() public méthode

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() public méthode

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() public méthode

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() public méthode

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() public méthode

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() public méthode

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() public méthode

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.