PHP Класс Arrayzy\AbstractArray

Автор: Victor Bocharsky ([email protected])
Наследование: implements ArrayAcces\ArrayAccess, implements Arrayzy\Interfaces\ConvertibleInterface, implements Countabl\Countable, implements Arrayzy\Interfaces\DebuggableInterface, implements IteratorAggregat\IteratorAggregate, implements Arrayzy\Interfaces\ModifiableInterface, implements Arrayzy\Interfaces\SortableInterface, implements Arrayzy\Interfaces\TraversableInterface, use trait Arrayzy\Traits\ConvertibleTrait, use trait Arrayzy\Traits\DebuggableTrait, use trait Arrayzy\Traits\ModifiableTrait, use trait Arrayzy\Traits\TraversableTrait
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$elements array

Открытые методы

Метод Описание
__construct ( array $elements = [] ) Construct new instance
chunk ( integer $size, boolean $preserveKeys = false ) : AbstractArray Create a chunked version of current array.
clear ( ) : AbstractArray Clear the current array.
combine ( array $array ) : AbstractArray Create an array using the current array as keys and the other array as values.
contains ( mixed $element ) : boolean Check if the given value exists in the array.
containsKey ( mixed $key ) : boolean Check if the given key/index exists in the array.
count ( ) : integer Returns the number of values in the array.
create ( array $elements = [] ) : AbstractArray Create a new instance.
createClone ( ) : AbstractArray Clone current instance to new instance.
createFromJson ( string $json, integer $options, integer $depth = 512 ) : AbstractArray Decode a JSON string to new instance.
createFromObject ( ArrayAccess $elements ) : AbstractArray Create a new instance filled with values from an object implementing ArrayAccess.
createFromString ( string $string, string $separator ) : AbstractArray Explode a string to new instance by specified separator.
createWithRange ( mixed $low, mixed $high, integer $step = 1 ) : AbstractArray Create a new instance containing a range of elements.
diff ( array $array ) : AbstractArray Compute the current array values which not present in the given one.
except ( array $keys ) : AbstractArray Return slice of an array except given keys.
exists ( callable $func ) : boolean Find the given value in An array using a closure
filter ( callable $func ) : AbstractArray Filter the current array for elements satisfying the predicate $func.
find ( callable $func ) : mixed Returns the first occurrence of a value that satisfies the predicate $func.
flip ( ) : AbstractArray Exchanges all keys of current array with their associated values.
getIterator ( ) : Traversable Create an iterator over this array.
getKeys ( ) : array Return an array all the keys of this array.
getRandom ( ) : mixed Pick a random value out of this array.
getRandomKey ( ) : mixed Pick a random key/index from the keys of this array.
getRandomKeys ( integer $number ) : mixed Pick a given number of random keys/indexes out of this array.
getRandomValues ( integer $number ) : array Pick a given number of random values with non-duplicate indexes out of the array.
getValues ( ) : mixed Return an array of all values from this array numerically indexed.
indexOf ( mixed $element ) : mixed Alias of search() method. Search for a given element and return the index of its first occurrence.
intersect ( array $array ) : AbstractArray Compute the current array values which present in the given one.
intersectAssoc ( array $array ) : AbstractArray Compute the current array values with additional index check which present in the given one.
intersectKey ( array $array ) : AbstractArray Compute the current array using keys for comparison which present in the given one.
isAssoc ( ) : boolean Check whether array is associative or not.
isEmpty ( ) : boolean Check whether the array is empty or not.
isNumeric ( ) : boolean Check whether array is numeric or not.
map ( callable $func ) : AbstractArray Apply the given function to the every element of the current array, collecting the results.
merge ( array $array, boolean $recursively = false ) : AbstractArray Merge the current array with the provided one. The latter array is overwriting.
offsetExists ( mixed $offset ) : boolean Whether an offset exists.
offsetGet ( mixed $offset ) : mixed Retrieve the current offset or null.
offsetSet ( mixed $offset, mixed $value ) Set an offset for this array.
offsetUnset ( mixed $offset ) Remove a present offset.
only ( array $keys ) : AbstractArray Return slice of an array with just a given keys.
pad ( integer $size, mixed $value ) : AbstractArray Pad the current array to the specified size with a given value.
reduce ( callable $func, mixed | null $initial = null ) : mixed Reduce the array to a single value iteratively combining all values using $func.
reindex ( ) : AbstractArray Create a numerically re-indexed array based on the current array.
replace ( array $array, boolean $recursively = false ) : AbstractArray Replace values in the current array with values in the given one that have the same key.
reverse ( boolean $preserveKeys = false ) : AbstractArray Reverse the values order of the current array.
search ( mixed $element ) : mixed Search for a given element and return the index of its first occurrence.
shuffle ( ) : AbstractArray Randomize elements order of the current array.
slice ( integer $offset, integer | null $length = null, boolean $preserveKeys = false ) : AbstractArray Extract a slice of the current array.
unique ( integer | null $sortFlags = null ) : AbstractArray Remove duplicate values from the current array.
walk ( callable $func, boolean $recursively = false ) : AbstractArray Apply the given function to the every element of the current array, discarding the results.

Приватные методы

Метод Описание
checkType ( string $type ) : boolean Check if an array keys are in a given variable type.

Описание методов

__construct() публичный метод

Construct new instance
public __construct ( array $elements = [] )
$elements array

chunk() абстрактный публичный метод

Create a chunked version of current array.
abstract public chunk ( integer $size, boolean $preserveKeys = false ) : AbstractArray
$size integer Size of each chunk
$preserveKeys boolean Whether array keys are preserved or no
Результат AbstractArray An array of chunks from the current array

clear() абстрактный публичный метод

Clear the current array.
abstract public clear ( ) : AbstractArray
Результат AbstractArray The current empty array

combine() абстрактный публичный метод

Create an array using the current array as keys and the other array as values.
abstract public combine ( array $array ) : AbstractArray
$array array Values array
Результат AbstractArray An array with values from the other array

contains() публичный метод

Check if the given value exists in the array.
public contains ( mixed $element ) : boolean
$element mixed Value to search for
Результат boolean Returns true if the given value exists in the array, false otherwise

containsKey() публичный метод

Check if the given key/index exists in the array.
public containsKey ( mixed $key ) : boolean
$key mixed Key/index to search for
Результат boolean Returns true if the given key/index exists in the array, false otherwise

count() публичный метод

Returns the number of values in the array.
public count ( ) : integer
Результат integer total number of values

create() публичный статический метод

Create a new instance.
public static create ( array $elements = [] ) : AbstractArray
$elements array
Результат AbstractArray Returns created instance

createClone() публичный метод

Clone current instance to new instance.
Устаревший: Should be removed
public createClone ( ) : AbstractArray
Результат AbstractArray Shallow copy of $this

createFromJson() публичный статический метод

Decode a JSON string to new instance.
public static createFromJson ( string $json, integer $options, integer $depth = 512 ) : AbstractArray
$json string The JSON string being decoded
$options integer Bitmask of JSON decode options
$depth integer Specified recursion depth
Результат AbstractArray The created array

createFromObject() публичный статический метод

Create a new instance filled with values from an object implementing ArrayAccess.
public static createFromObject ( ArrayAccess $elements ) : AbstractArray
$elements ArrayAccess Object that implements ArrayAccess
Результат AbstractArray Returns created instance

createFromString() публичный статический метод

Explode a string to new instance by specified separator.
public static createFromString ( string $string, string $separator ) : AbstractArray
$string string Converted string
$separator string Element's separator
Результат AbstractArray The created array

createWithRange() публичный статический метод

Create a new instance containing a range of elements.
public static createWithRange ( mixed $low, mixed $high, integer $step = 1 ) : AbstractArray
$low mixed First value of the sequence
$high mixed The sequence is ended upon reaching the end value
$step integer Used as the increment between elements in the sequence
Результат AbstractArray The created array

diff() абстрактный публичный метод

Compute the current array values which not present in the given one.
abstract public diff ( array $array ) : AbstractArray
$array array Array for diff
Результат AbstractArray An array containing all the entries from this array that are not present in $array

except() публичный метод

Return slice of an array except given keys.
public except ( array $keys ) : AbstractArray
$keys array List of keys to exclude
Результат AbstractArray The created array

exists() публичный метод

Find the given value in An array using a closure
public exists ( callable $func ) : boolean
$func callable
Результат boolean Returns true if the given value is found, false otherwise

filter() абстрактный публичный метод

Filter the current array for elements satisfying the predicate $func.
abstract public filter ( callable $func ) : AbstractArray
$func callable
Результат AbstractArray An array with only element satisfying $func

find() публичный метод

Returns the first occurrence of a value that satisfies the predicate $func.
public find ( callable $func ) : mixed
$func callable
Результат mixed The first occurrence found

flip() абстрактный публичный метод

Exchanges all keys of current array with their associated values.
abstract public flip ( ) : AbstractArray
Результат AbstractArray An array with flipped elements

getIterator() публичный метод

Create an iterator over this array.
public getIterator ( ) : Traversable
Результат Traversable An instance of an object implementing Iterator

getKeys() публичный метод

Return an array all the keys of this array.
public getKeys ( ) : array
Результат array An array of all keys

getRandom() публичный метод

Pick a random value out of this array.
public getRandom ( ) : mixed
Результат mixed Random value of array

getRandomKey() публичный метод

Pick a random key/index from the keys of this array.
public getRandomKey ( ) : mixed
Результат mixed Random key/index of array

getRandomKeys() публичный метод

Pick a given number of random keys/indexes out of this array.
public getRandomKeys ( integer $number ) : mixed
$number integer The number of keys/indexes (should be <= $this->count())
Результат mixed Random keys or key of array

getRandomValues() публичный метод

Pick a given number of random values with non-duplicate indexes out of the array.
public getRandomValues ( integer $number ) : array
$number integer The number of values (should be > 1 and < $this->count())
Результат array Random values of array

getValues() публичный метод

Return an array of all values from this array numerically indexed.
public getValues ( ) : mixed
Результат mixed An array of all values

indexOf() публичный метод

Alias of search() method. Search for a given element and return the index of its first occurrence.
public indexOf ( mixed $element ) : mixed
$element mixed Value to search for
Результат mixed The corresponding key/index

intersect() абстрактный публичный метод

Compute the current array values which present in the given one.
abstract public intersect ( array $array ) : AbstractArray
$array array Array for intersect
Результат AbstractArray An array with containing all the entries from this array that are present in $array

intersectAssoc() абстрактный публичный метод

Compute the current array values with additional index check which present in the given one.
abstract public intersectAssoc ( array $array ) : AbstractArray
$array array Array for intersect
Результат AbstractArray An array with containing all the entries from this array that are present in $array. Note that the keys are also used in the comparison unlike in intersect().

intersectKey() абстрактный публичный метод

Compute the current array using keys for comparison which present in the given one.
abstract public intersectKey ( array $array ) : AbstractArray
$array array Array for intersect
Результат AbstractArray An array with containing all the entries from this array which have keys that are present in $array.

isAssoc() публичный метод

Check whether array is associative or not.
public isAssoc ( ) : boolean
Результат boolean Returns true if associative, false otherwise

isEmpty() публичный метод

Check whether the array is empty or not.
public isEmpty ( ) : boolean
Результат boolean Returns true if empty, false otherwise

isNumeric() публичный метод

Check whether array is numeric or not.
public isNumeric ( ) : boolean
Результат boolean Returns true if numeric, false otherwise

map() абстрактный публичный метод

Apply the given function to the every element of the current array, collecting the results.
abstract public map ( callable $func ) : AbstractArray
$func callable
Результат AbstractArray An array with modified elements

merge() абстрактный публичный метод

Merge the current array with the provided one. The latter array is overwriting.
abstract public merge ( array $array, boolean $recursively = false ) : AbstractArray
$array array Array to merge with (overwrites)
$recursively boolean Whether array will be merged recursively or no
Результат AbstractArray An array with the keys/values from $array added

offsetExists() публичный метод

Whether an offset exists.
public offsetExists ( mixed $offset ) : boolean
$offset mixed An offset to check for.
Результат boolean true on success or false on failure.

offsetGet() публичный метод

Retrieve the current offset or null.
public offsetGet ( mixed $offset ) : mixed
$offset mixed The offset to retrieve.
Результат mixed Can return all value types.

offsetSet() публичный метод

Set an offset for this array.
public offsetSet ( mixed $offset, mixed $value )
$offset mixed The offset to assign the value to.
$value mixed The value to set.

offsetUnset() публичный метод

Remove a present offset.
public offsetUnset ( mixed $offset )
$offset mixed The offset to unset.

only() публичный метод

Return slice of an array with just a given keys.
public only ( array $keys ) : AbstractArray
$keys array List of keys to return
Результат AbstractArray The created array

pad() абстрактный публичный метод

Pad the current array to the specified size with a given value.
abstract public pad ( integer $size, mixed $value ) : AbstractArray
$size integer Size of the result array
$value mixed Empty value by default
Результат AbstractArray An array padded to $size with $value

reduce() публичный метод

Reduce the array to a single value iteratively combining all values using $func.
public reduce ( callable $func, mixed | null $initial = null ) : mixed
$func callable callback ($carry, $item) -> next $carry
$initial mixed | null starting value of the $carry
Результат mixed Final value of $carry

reindex() абстрактный публичный метод

Create a numerically re-indexed array based on the current array.
abstract public reindex ( ) : AbstractArray
Результат AbstractArray An array with re-indexed elements

replace() абстрактный публичный метод

Replace values in the current array with values in the given one that have the same key.
abstract public replace ( array $array, boolean $recursively = false ) : AbstractArray
$array array Array of replacing values
$recursively boolean Whether array will be replaced recursively or no
Результат AbstractArray An array with the same keys but new values

reverse() абстрактный публичный метод

Reverse the values order of the current array.
abstract public reverse ( boolean $preserveKeys = false ) : AbstractArray
$preserveKeys boolean Whether array keys are preserved or no
Результат AbstractArray An array with the order of the elements reversed

shuffle() абстрактный публичный метод

Randomize elements order of the current array.
abstract public shuffle ( ) : AbstractArray
Результат AbstractArray An array with the shuffled elements order

slice() абстрактный публичный метод

Extract a slice of the current array.
abstract public slice ( integer $offset, integer | null $length = null, boolean $preserveKeys = false ) : AbstractArray
$offset integer Slice begin index
$length integer | null Length of the slice
$preserveKeys boolean Whether array keys are preserved or no
Результат AbstractArray A new array, which is slice of the current array with specified $length

unique() абстрактный публичный метод

Remove duplicate values from the current array.
abstract public unique ( integer | null $sortFlags = null ) : AbstractArray
$sortFlags integer | null
Результат AbstractArray An array with only unique elements

walk() абстрактный публичный метод

Apply the given function to the every element of the current array, discarding the results.
abstract public walk ( callable $func, boolean $recursively = false ) : AbstractArray
$func callable
$recursively boolean Whether array will be walked recursively or no
Результат AbstractArray An array with modified elements

Описание свойств

$elements защищенное свойство

protected array $elements
Результат array