- Notifications
You must be signed in to change notification settings - Fork34
🗃 Array manipulation library for PHP, called Arrayy!
License
voku/Arrayy
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A PHP array manipulation library. Compatible with PHP 7+ & PHP 8+
\Arrayy\Type\StringCollection::create(['Array','Array'])->unique()->append('y')->implode()// Arrayy
- Installation
- Multidimensional ArrayAccess
- PhpDoc @property checking
- OO and Chaining
- Collections
- Class methods
- Instance methods
- Tests
- License
composer require voku/arrayy
You can access / change the array via Object, Array or with "Arrayy"-syntax.
$arrayy =newA(['Lars' => ['lastname' =>'Moelleken']]);$arrayy->get('Lars');// ['lastname' => 'Moelleken']$arrayy->get('Lars.lastname');// 'Moelleken'
$arrayy =newA(['Lars' => ['lastname' =>'Moelleken']]);$arrayy['Lars'];// ['lastname' => 'Moelleken']$arrayy['Lars']['lastname'];// 'Moelleken'
$arrayy =newA(['Lars' => ['lastname' =>'Moelleken']]);$arrayy->Lars;// Arrayy['lastname' => 'Moelleken']$arrayy->Lars->lastname;// 'Moelleken'
$arrayy =newA(['Lars' => ['lastname' =>'Mueller']]);$arrayy->set('Lars.lastname','Moelleken');$arrayy->get('Lars.lastname');// 'Moelleken'
$arrayy =newA(['Lars' => ['lastname' =>'Moelleken']]);$arrayy['Lars'] =array('lastname' =>'Müller');$arrayy['Lars']['lastname'];// 'Müller'
$arrayy =newA(['Lars' => ['lastname' =>'Moelleken']]);$arrayy->Lars =array('lastname' =>'Müller');$arrayy->Lars->lastname;// 'Müller'
The library offers a type checking for @property phpdoc-class-comments, as seen below:
/** * @property int $id * @property int|string $firstName * @property string $lastName * @property null|City $city * * @extends \Arrayy\Arrayy<array-key,mixed> */class Userextends \Arrayy\Arrayy{protected$checkPropertyTypes =true;protected$checkPropertiesMismatchInConstructor =true;}/** * @property string|null $plz * @property string $name * @property string[] $infos * * @extends \Arrayy\Arrayy<array-key,mixed> */class Cityextends \Arrayy\Arrayy{protected$checkPropertyTypes =true;protected$checkPropertiesMismatchInConstructor =true;}$cityMeta = City::meta();$city =newCity( [$cityMeta->plz =>null,$cityMeta->name =>'Düsseldorf',$cityMeta->infos => ['lall'], ]);$userMeta = User::meta();$user =newUser( [$userMeta->id =>1,$userMeta->firstName =>'Lars',$userMeta->lastName =>'Moelleken',$userMeta->city =>$city, ]);var_dump($user['lastName']);// 'Moelleken'var_dump($user[$userMeta->lastName]);// 'Moelleken'var_dump($user->lastName);// Moellekenvar_dump($user['city.name']);// 'Düsseldorf'var_dump($user[$userMeta->city][$cityMeta->name]);// 'Düsseldorf'var_dump($user->city->name);// Düsseldorf
- "checkPropertyTypes": activate the type checking for all defined @property in the class-phpdoc
- "checkPropertiesMismatchInConstructor": activate the property mismatch check, so you can only add anarray with all needed properties (or an empty array) into the constructor
The library also offers OO method chaining, as seen below:
simple example:
echoa(['fòô','bàř','bàř'])->unique()->reverse()->implode(',');// 'bàř,fòô'
complex example:
/** * @property int $id * @property string $firstName * @property string $lastName * * @extends \Arrayy\Arrayy<array-key,mixed> */class Userextends \Arrayy\Arrayy{protected$checkPropertyTypes =true;protected$checkPropertiesMismatchInConstructor =true;}/** * @template TKey of array-key * @extends AbstractCollection<TKey,User> */class UserCollectionextends \Arrayy\Collection\AbstractCollection{/** * The type (FQCN) associated with this collection. * * @return string */publicfunctiongetType() {return User::class; }}$m = User::meta();$data =staticfunction ()use ($m) {yieldnewUser([$m->id =>40,$m->firstName =>'Foo',$m->lastName =>'Moelleken']);yieldnewUser([$m->id =>30,$m->firstName =>'Sven',$m->lastName =>'Moelleken']);yieldnewUser([$m->id =>20,$m->firstName =>'Lars',$m->lastName =>'Moelleken']);yieldnewUser([$m->id =>10,$m->firstName =>'Lea',$m->lastName =>'Moelleken']);};$users = UserCollection::createFromGeneratorFunction($data);$names =$users ->filter(staticfunction (User$user):bool {return$user->id <=30; }) ->customSortValuesImmutable(staticfunction (User$a,User$b):int {return$a->firstName <=>$b->firstName; }) ->map(staticfunction (User$user):string {return$user->firstName; }) ->implode(';');static::assertSame('Lars;Lea;Sven',$names);
Arrayy\Arrayy
implements theIteratorAggregate
interface, meaning thatforeach
can be used with an instance of the class:
$arrayy =a(['fòôbàř','foo']);foreach ($arrayyas$value) {echo$value;}// 'fòôbàř'// 'foo'
It implements theCountable
interface, enabling the use ofcount()
toretrieve the number of elements in the array:
$arrayy =a(['fòô','foo']);count($arrayy);// 2
As of PHP 5.6,use function
isavailable for importing functions. Arrayy exposes a namespaced function,Arrayy\create
, which emits the same behaviour asArrayy\Arrayy::create()
.If running PHP 5.6, or another runtime that supports theuse function
syntax,you can take advantage of an even simpler API as seen below:
usefunctionArrayy\createasa;// Instead of: A::create(['fòô', 'bàř'])->reverse()->implode();a(['fòô','bàř'])->reverse()->implode(',');// 'bàř,fòô'
If you need to group objects together, it's not a good ideato use a simple array or Arrayy object. For these cases you can use theAbstractCollection
class.
It will throw aInvalidArgumentException
if you try to add a non valid object into the collection.
e.g.: "YOURCollection.php" (see example/tests/CollectionTest.php
on github)
useArrayy\Collection\AbstractCollection;/** * @extends AbstractCollection<array-key,YOURInterface> */class YOURCollectionextends AbstractCollection{/** * The type (FQCN) associated with this collection. * * @return string */publicfunctiongetType():string {return YOURInterface::class; }}$YOURobject1 =newYOURClass();$YOURobject2 =newYOURClass();$YOURcollection =newYOURCollection($YOURobject1);$YOURcollection->add($YOURobject2);// add one more object// Or, you can use an array of objects.//// $YOURcollection = new YOURCollection([$YOURobject1, $YOURobject2]);// Or, if you don't want to create new classes ...// ... and you don't need typehints and autocompletion via classes.//// $YOURcollection = \Arrayy\Collection::construct(YOURInterface::class, [$YOURobject1]);// $YOURcollection->add($YOURobject2); // add one more object// Or, if you don't like classes at all. ;-)//// $YOURcollection = \Arrayy\collection(YOURInterface::class, [$YOURobject1]);// $YOURcollection->add($YOURobject2); // add one more objectforeach ($YOURcollectionas$YOURobject) {if ($YOURobjectinstanceof YOURInterface) {// Do something with $YOURobject }}
You can also use "dot-notation" to get data from your collections e.g.$YOURcollection->get('3123.foo.bar');
This will throw a "TypeError"-Exception.
useArrayy\Type\StringCollection;$collection =newStringCollection(['A','B','C',1]);
This will NOT throw a "TypeError"-Exception.
useArrayy\Type\IntCollection;useArrayy\Type\StringCollection;useArrayy\Type\InstancesCollection;useArrayy\Type\TypeInterface;$collection = InstancesCollection::construct( TypeInterface::class, [newStringCollection(['A','B','C']),newIntCollection([1])]);$collection->toArray(true);// [['A', 'B', 'C'], [1]]
namespaceArrayy\tests\Collection;useArrayy\Collection\AbstractCollection;/** * @extends AbstractCollection<array-key,\Arrayy\tests\UserData> */class UserDataCollectionextends AbstractCollection{/** * The type (FQCN) associated with this collection. * * @return string */publicfunctiongetType() {return \Arrayy\tests\UserData::class; }}$json ='[{"id":1,"firstName":"Lars","lastName":"Moelleken","city":{"name":"Düsseldorf","plz":null,"infos":["lall"]}}, {"id":1,"firstName":"Sven","lastName":"Moelleken","city":{"name":"Köln","plz":null,"infos":["foo"]}}]';$userDataCollection = UserDataCollection::createFromJsonMapper($json);/** @var \Arrayy\tests\UserData[] $userDatas */$userDataCollection->getAll();$userData0 =$userDataCollection[0];echo$userData0->firstName;// 'Lars'$userData0->city;// CityData::classecho$userData0->city->name;// 'Düsseldorf'$userData1 =$userDataCollection[1];echo$userData1->firstName;// 'Sven'$userData1->city;// CityData::classecho$userData1->city->name;// 'Köln'
Creates an Arrayy object.
$arrayy =newArrayy(array('fòô','bàř'));// Arrayy['fòô', 'bàř']
Creates an Arrayy object, via static "create()"-method
$arrayy = A::create(array('fòô','bàř'));// Arrayy['fòô', 'bàř']
WARNING: Creates an Arrayy object by reference.
$array =array('fòô','bàř');$arrayy = A::createByReference($array);// Arrayy['fòô', 'bàř']
Create an new Arrayy object via JSON.
$str ='{"firstName":"John", "lastName":"Doe"}';$arrayy = A::createFromJson($str);// Arrayy['firstName' => 'John', 'lastName' => 'Doe']
Create an new Arrayy object via JSON and fill sub-objects is possible.
<?phpnamespaceArrayy\tests;/** * @property int $id * @property int|string $firstName * @property string $lastName * @property \Arrayy\tests\CityData|null $city * * @extends \Arrayy\Arrayy<array-key,mixed> */class UserDataextends \Arrayy\Arrayy{protected$checkPropertyTypes =true;protected$checkForMissingPropertiesInConstructor =true;}/** * @property string|null $plz * @property string $name * @property string[] $infos * * @extends \Arrayy\Arrayy<array-key,mixed> */class CityDataextends \Arrayy\Arrayy{protected$checkPropertyTypes =true;protected$checkPropertiesMismatchInConstructor =true;protected$checkForMissingPropertiesInConstructor =true;protected$checkPropertiesMismatch =true;}$json ='{"id":1,"firstName":"Lars","lastName":"Moelleken","city":{"name":"Düsseldorf","plz":null,"infos":["lall"]}}';$userData = UserData::createFromJsonMapper($json);$userData;// => \Arrayy\tests\UserData::classecho$userData->firstName;// 'Lars'$userData->city;// => \Arrayy\tests\CityData::classecho$userData->city->name;// 'Düsseldorf'
Create an new instance filled with values from an object that have implemented ArrayAccess.
$object = A::create(1,'foo');$arrayy = A::createFromObject($object);// Arrayy[1, 'foo']
Create an new instance filled with values from an object.
$object =newstdClass();$object->x =42;$arrayy = A::createFromObjectVars($object);// Arrayy['x' => 42]
Create an new instance containing a range of elements.
$arrayy = A::createWithRange(2,4);// Arrayy[2, 3, 4]
Create an new instance filled with a copy of values from a "Generator"-object.
WARNING: Need more memory then the "A::createFromGeneratorFunction()" call, because wewill fetch and store all keys and values from the Generator.
$generator = A::createWithRange(2,4)->getGenerator();$arrayy = A::createFromGeneratorImmutable($generator);// Arrayy[2, 3, 4]
Create an new instance from a callable function which will return a Generator.
$generatorFunction =staticfunction() {yieldfrom A::createWithRange(2,4)->getArray();};$arrayy = A::createFromGeneratorFunction($generatorFunction);// Arrayy[2, 3, 4]
Create an new Arrayy object via string.
$arrayy = A::createFromString(' foo, bar');// Arrayy['foo', 'bar']
Arrayy: All examples below make use of PHP 5.6function importing, and PHP 5.4 short array syntax. For further details,see the documentation for the create method above, as well as the noteson PHP 5.6 creation.
$arrayy =a(['fòô' =>'bàř']);$arrayy['foo'] ='bar';var_dump($arrayy);// Arrayy['fòô' => 'bàř', 'foo' => 'bar']
$arrayy =a(['fòô' =>'bàř']);var_dump($arrayy['fòô']);// 'bàř'
$arrayy =a(['fòô' =>'bàř']);var_dump($arrayy->getArray());// ['fòô' => 'bàř']
$arrayy =a(['fòô' =>'bàř','lall']);unset($arrayy['fòô']);var_dump($arrayy);// Arrayy[0 => 'lall']
$arrayy =a(['fòô' =>'bàř']);isset($arrayy['fòô']);// true
$arrayy =a(['fòô' =>'bàř']);foreach ($arrayy)as$key =>$value) {echo$key .' |' .$value;// fòô | bàř}
↑Add new values (optional using dot-notation).
Parameters:
T $value
TKey $key
Return:
static <p>(Immutable) Return this Arrayy object, with the appended values.</p>
↑Append a (key) + value to the current array.
EXAMPLE:a(['fòô' => 'bàř'])->append('foo'); // Arrayy['fòô' => 'bàř', 0 => 'foo']
Parameters:
T $value
TKey|null $key
Return:
$this <p>(Mutable) Return this Arrayy object, with the appended values.</p>
↑Append a (key) + values to the current array.
EXAMPLE:a(['fòô' => ['bàř']])->appendArrayValues(['foo1', 'foo2'], 'fòô'); // Arrayy['fòô' => ['bàř', 'foo1', 'foo2']]
Parameters:
array<T> $values
TKey|null $key
Return:
$this <p>(Mutable) Return this Arrayy object, with the appended values.</p>
↑Append a (key) + value to the current array.
EXAMPLE:a(['fòô' => 'bàř'])->appendImmutable('foo')->getArray(); // ['fòô' => 'bàř', 0 => 'foo']
Parameters:
T $value
TKey $key
Return:
$this <p>(Immutable) Return this Arrayy object, with the appended values.</p>
↑Add a suffix to each key.
Parameters:
int|string $prefix
Return:
static <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p>
↑Add a prefix to each value.
Parameters:
float|int|string $prefix
Return:
static <p>(Immutable) Return an Arrayy object, with the prefixed values.</p>
↑Sort an array in reverse order and maintain index association.
Parameters:nothing
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Sort an array in reverse order and maintain index association.
Parameters:nothing
Return:
$this <p>(Immutable) Return this Arrayy object.</p>
↑Sort the entries by value.
Parameters:
- `int $sort_flags [optional]
You may modify the behavior of the sort using the optionalparameter sort_flags, for detailssee sort.
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Sort the entries by value.
Parameters:
- `int $sort_flags [optional]
You may modify the behavior of the sort using the optionalparameter sort_flags, for detailssee sort.
Return:
$this <p>(Immutable) Return this Arrayy object.</p>
↑Iterate over the current array and execute a callback for each loop.
EXAMPLE:$result = A::create();$closure = function ($value, $key) use ($result) {$result[$key] = ':' . $value . ':';};a(['foo', 'bar' => 'bis'])->at($closure); // Arrayy[':foo:', 'bar' => ':bis:']
Parameters:
\Closure(T , TKey ): mixed $closure
Return:
static <p>(Immutable)</p>
↑Returns the average value of the current array.
EXAMPLE:a([-9, -8, -7, 1.32])->average(2); // -5.67
Parameters:
int $decimals <p>The number of decimal-numbers to return.</p>
Return:
float|int <p>The average value.</p>
↑Changes all keys in an array.
Parameters:
int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> or <strong>CASE_LOWER</strong> (default)</p>
Return:
static <p>(Immutable)</p>
↑Change the path separator of the array wrapper.
By default, the separator is: "."
Parameters:
non-empty-string $separator <p>Separator to set.</p>
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Create a chunked version of the current array.
EXAMPLE:a([-9, -8, -7, 1.32])->chunk(2); // Arrayy[[-9, -8], [-7, 1.32]]
Parameters:
int $size <p>Size of each chunk.</p>
bool $preserveKeys <p>Whether array keys are preserved or no.</p>
Return:
static|static[] <p>(Immutable) A new array of chunks from the original array.</p>
↑Clean all falsy values from the current array.
EXAMPLE:a([-8 => -9, 1, 2 => false])->clean(); // Arrayy[-8 => -9, 1]
Parameters:nothing
Return:
static <p>(Immutable)</p>
↑WARNING!!! -> Clear the current full array or a $key of it.
EXAMPLE:a([-8 => -9, 1, 2 => false])->clear(); // Arrayy[]
Parameters:
int|int[]|string|string[]|null $key
Return:
$this <p>(Mutable) Return this Arrayy object, with an empty array.</p>
↑Check if an item is in the current array.
EXAMPLE:a([1, true])->contains(true); // true
Parameters:
float|int|string $value
bool $recursive
bool $strict
Return:
bool
↑Check if an (case-insensitive) string is in the current array.
EXAMPLE:a(['E', 'é'])->containsCaseInsensitive('É'); // true
Parameters:
mixed $value
bool $recursive
Return:
bool
↑Check if the given key/index exists in the array.
EXAMPLE:a([1 => true])->containsKey(1); // true
Parameters:
int|string $key <p>key/index to search for</p>
Return:
bool <p>Returns true if the given key/index exists in the array, false otherwise.</p>
↑Check if all given needles are present in the array as key/index.
EXAMPLE:a([1 => true])->containsKeys(array(1 => 0)); // true
Parameters:
array<TKey> $needles <p>The keys you are searching for.</p>
bool $recursive
Return:
bool <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p>
↑Check if all given needles are present in the array as key/index.
Parameters:
array<TKey> $needles <p>The keys you are searching for.</p>
Return:
bool <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p>
↑Check if an item is in the current array.
EXAMPLE:a([1, true])->containsOnly(true); // false
Parameters:
float|int|string $value
bool $recursive
bool $strict
Return:
bool
↑alias: for "Arrayy->contains()"
Parameters:
float|int|string $value
Return:
bool
↑alias: for "Arrayy->contains($value, true)"
Parameters:
float|int|string $value
Return:
bool
↑Check if all given needles are present in the array.
EXAMPLE:a([1, true])->containsValues(array(1, true)); // true
Parameters:
array<T> $needles
Return:
bool <p>Returns true if all the given values exists in the array, false otherwise.</p>
↑Counts all elements in an array, or something in an object.
EXAMPLE:a([-9, -8, -7, 1.32])->count(); // 4
For objects, if you have SPL installed, you can hook into count() by implementing interface {@see \Countable}.The interface has exactly one method, {@see \Countable::count()}, which returns the return value for the count()function. Please see the {@see \Array} section of the manual for a detailed explanation of how arrays areimplemented and used in PHP.
Parameters:
int $mode [optional] If the optional mode parameter is set to COUNT_RECURSIVE (or 1), count will recursively count the array. This is particularly useful for counting all the elements of a multidimensional array. count does not detect infinite recursion.
Return:
- `int
The number of elements in var, which istypically an array, since anything else will have oneelement.
If var is not an array or an object withimplemented Countable interface,1 will be returned.There is one exception, if var is &null;,0 will be returned.
Caution: count may return 0 for a variable that isn't set,but it may also return 0 for a variable that has been initialized with anempty array. Use isset to test if a variable is set.
`↑Counts all the values of an array
Parameters:nothing
Return:
- `static
(Immutable)An associative Arrayy-object of values from input askeys and their count as value.
↑Creates an Arrayy object.
Parameters:
mixed $data
class-string<\Arrayy\ArrayyIterator> $iteratorClass
bool $checkPropertiesInConstructor
Return:
static <p>(Immutable) Returns an new instance of the Arrayy object.</p>
↑WARNING: Creates an Arrayy object by reference.
Parameters:
array $array
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Create an new Arrayy object via JSON.
Parameters:
array $array
Return:
static <p>(Immutable) Returns an new instance of the Arrayy object.</p>
↑Create an new instance from a callable function which will return an Generator.
Parameters:
callable(): \Generator<TKey, T> $generatorFunction
Return:
static <p>(Immutable) Returns an new instance of the Arrayy object.</p>
↑Create an new instance filled with a copy of values from a "Generator"-object.
Parameters:
\Generator<TKey, T> $generator
Return:
static <p>(Immutable) Returns an new instance of the Arrayy object.</p>
↑Create an new Arrayy object via JSON.
Parameters:
string $json
Return:
static <p>(Immutable) Returns an new instance of the Arrayy object.</p>
Parameters:
string $json
Return:
static <p>(Immutable)</p>
↑Create an new instance filled with values from an object that is iterable.
Parameters:
\Traversable<array-key, T> $object <p>iterable object</p>
Return:
static <p>(Immutable) Returns an new instance of the Arrayy object.</p>
↑Create an new instance filled with values from an object.
Parameters:
object $object
Return:
static <p>(Immutable) Returns an new instance of the Arrayy object.</p>
↑Create an new Arrayy object via string.
Parameters:
string $str <p>The input string.</p>
non-empty-string|null $delimiter <p>The boundary string.</p>
string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be used.</p>
Return:
static <p>(Immutable) Returns an new instance of the Arrayy object.</p>
↑Create an new instance filled with a copy of values from a "Traversable"-object.
Parameters:
\Traversable<(array-key|TKey), T> $traversable
- `bool $use_keys [optional]
Whether to use the iterator element keys as index.
Return:
static <p>(Immutable) Returns an new instance of the Arrayy object.</p>
↑Create an new instance containing a range of elements.
Parameters:
float|int|string $low <p>First value of the sequence.</p>
float|int|string $high <p>The sequence is ended upon reaching the end value.</p>
float|int $step <p>Used as the increment between elements in the sequence.</p>
Return:
static <p>(Immutable) Returns an new instance of the Arrayy object.</p>
↑Gets the element of the array at the current internal iterator position.
Parameters:nothing
Return:
false|mixed
↑Custom sort by index via "uksort".
EXAMPLE:$callable = function ($a, $b) {if ($a == $b) {return 0;}return ($a > $b) ? 1 : -1;};$arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]);$resultArrayy = $arrayy->customSortKeys($callable); // Arrayy['one' => 1, 'three' => 3, 'two' => 2]
Parameters:
callable $callable
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Custom sort by index via "uksort".
Parameters:
callable $callable
Return:
$this <p>(Immutable) Return this Arrayy object.</p>
↑Custom sort by value via "usort".
EXAMPLE:$callable = function ($a, $b) {if ($a == $b) {return 0;}return ($a > $b) ? 1 : -1;};$arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]);$resultArrayy = $arrayy->customSortValues($callable); // Arrayy[1, 2, 3]
Parameters:
callable $callable
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Custom sort by value via "usort".
Parameters:
callable $callable
Return:
$this <p>(Immutable) Return this Arrayy object.</p>
↑Delete the given key or keys.
Parameters:
int|int[]|string|string[] $keyOrKeys
Return:
void
↑Return elements where the values that are only in the current array.
EXAMPLE:a([1 => 1, 2 => 2])->diff([1 => 1]); // Arrayy[2 => 2]
Parameters:
array ...$array
Return:
static <p>(Immutable)</p>
↑Return elements where the keys are only in the current array.
Parameters:
array ...$array
Return:
static <p>(Immutable)</p>
↑Return elements where the values and keys are only in the current array.
Parameters:
array ...$array
Return:
static <p>(Immutable)</p>
↑Return elements where the values are only in the current multi-dimensional array.
EXAMPLE:a([1 => [1 => 1], 2 => [2 => 2]])->diffRecursive([1 => [1 => 1]]); // Arrayy[2 => [2 => 2]]
Parameters:
array $array
null|array<TKey, T>|\Generator<TKey, T> $helperVariableForRecursion <p>(only for internal usage)</p>
Return:
static <p>(Immutable)</p>
↑Return elements where the values that are only in the new $array.
EXAMPLE:a([1 => 1])->diffReverse([1 => 1, 2 => 2]); // Arrayy[2 => 2]
Parameters:
array $array
Return:
static <p>(Immutable)</p>
↑Divide an array into two arrays. One with keys and the other with values.
EXAMPLE:a(['a' => 1, 'b' => ''])->divide(); // Arrayy[Arrayy['a', 'b'], Arrayy[1, '']]
Parameters:nothing
Return:
static <p>(Immutable)</p>
↑Iterate over the current array and modify the array's value.
EXAMPLE:$result = A::create();$closure = function ($value) {return ':' . $value . ':';};a(['foo', 'bar' => 'bis'])->each($closure); // Arrayy[':foo:', 'bar' => ':bis:']
Parameters:
\Closure(T , ?TKey ): T $closure
Return:
static <p>(Immutable)</p>
↑Sets the internal iterator to the last element in the array and returns this element.
Parameters:nothing
Return:
false|mixed
↑Exchange the array for another one.
Parameters:
- `T|array<TKey, T>|self<TKey, T> $data 1. use the current array, if it's a array
- fallback to empty array, if there is nothing
- call "getArray()" on object, if there is a "Arrayy"-object
- call "createFromObject()" on object, if there is a "\Traversable"-object
- call "__toArray()" on object, if the method exists
- cast a string or object with "__toString()" into an array
- throw a "InvalidArgumentException"-Exception`
Return:
array
↑Check if a value is in the current array using a closure.
EXAMPLE:$callable = function ($value, $key) {return 2 === $key and 'two' === $value;};a(['foo', 2 => 'two'])->exists($callable); // true
Parameters:
\Closure(T , TKey ): bool $closure
Return:
bool <p>Returns true if the given value is found, false otherwise.</p>
↑Fill the array until "$num" with "$default" values.
EXAMPLE:a(['bar'])->fillWithDefaults(3, 'foo'); // Arrayy['bar', 'foo', 'foo']
Parameters:
int $num
T $default
Return:
static <p>(Immutable)</p>
↑Find all items in an array that pass the truth test.
EXAMPLE:$closure = function ($value) {return $value % 2 !== 0;}a([1, 2, 3, 4])->filter($closure); // Arrayy[0 => 1, 2 => 3]
Parameters:
- `null|\Closure(T , TKey = default): bool|\Closure(T ): bool|\Closure(TKey ): bool $closure [optional]
The callback function to use
If no callback is supplied, all entries ofinput equal to false (seeconverting toboolean) will be removed.
`- `int $flag [optional]Flag determining what arguments are sent tocallback:
- ARRAY_FILTER_USE_KEY (1) - pass key as the only argumenttocallback instead of the value
- ARRAY_FILTER_USE_BOTH (2) - pass both value and key asarguments tocallback instead of the value
Return:
static <p>(Immutable)</p>
↑Filters an array of objects (or a numeric array of associative arrays) based on the value of a particularproperty within that.
Parameters:
string $property
array|T $value
- `string|null $comparisonOp
'eq' (equals),
'gt' (greater),
'gte' || 'ge' (greater or equals),
'lt' (less),
'lte' || 'le' (less or equals),
'ne' (not equals),
'contains',
'notContains',
'newer' (via strtotime),
'older' (via strtotime),
Return:
static <p>(Immutable)</p>
↑Find the first item in an array that passes the truth test, otherwise return false.
EXAMPLE:$search = 'foo';$closure = function ($value, $key) use ($search) {return $value === $search;};a(['foo', 'bar', 'lall'])->find($closure); // 'foo'
Parameters:
\Closure(T , TKey ): bool $closure
Return:
false|mixed <p>Return false if we did not find the value.</p>
↑find by ...
EXAMPLE:$array = [0 => ['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456, 'when' => '2014-01-01'],1 => ['id' => 456, 'name' => 'bar', 'group' => 'primary', 'value' => 1468, 'when' => '2014-07-15'],];a($array)->filterBy('name', 'foo'); // Arrayy[0 => ['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456, 'when' => '2014-01-01']]
Parameters:
string $property
array|T $value
string $comparisonOp
Return:
static <p>(Immutable)</p>
↑Get the first value from the current array.
EXAMPLE:a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->first(); // 'foo'
Parameters:nothing
Return:
mixed|null <p>Return null if there wasn't a element.</p>
↑Get the first key from the current array.
Parameters:nothing
Return:
mixed|null <p>Return null if there wasn't a element.</p>
↑Get the first value(s) from the current array.
And will return an empty array if there was no first entry.
EXAMPLE:a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->firstsImmutable(2); // Arrayy[0 => 'foo', 1 => 'bar']
Parameters:
int|null $number <p>How many values you will take?</p>
Return:
static <p>(Immutable)</p>
↑Get the first value(s) from the current array.
And will return an empty array if there was no first entry.
Parameters:
int|null $number <p>How many values you will take?</p>
Return:
static <p>(Immutable)</p>
↑Get and remove the first value(s) from the current array.
And will return an empty array if there was no first entry.
EXAMPLE:a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->firstsMutable(); // 'foo'
Parameters:
int|null $number <p>How many values you will take?</p>
Return:
$this <p>(Mutable)</p>
↑Flatten an array with the given character as a key delimiter.
EXAMPLE:$dot = a(['foo' => ['abc' => 'xyz', 'bar' => ['baz']]]);$flatten = $dot->flatten();$flatten['foo.abc']; // 'xyz'$flatten['foo.bar.0']; // 'baz'
Parameters:
string $delimiter
string $prepend
array|null $items
Return:
array
↑Exchanges all keys with their associated values in an array.
EXAMPLE:a([0 => 'foo', 1 => 'bar'])->flip(); // Arrayy['foo' => 0, 'bar' => 1]
Parameters:nothing
Return:
static <p>(Immutable)</p>
↑Get a value from an array (optional using dot-notation).
EXAMPLE:$arrayy = a(['user' => ['lastname' => 'Moelleken']]);$arrayy->get('user.lastname'); // 'Moelleken'// ---$arrayy = new A();$arrayy['user'] = ['lastname' => 'Moelleken'];$arrayy['user.firstname'] = 'Lars';$arrayy['user']['lastname']; // Moelleken$arrayy['user.lastname']; // Moelleken$arrayy['user.firstname']; // Lars
Parameters:
TKey $key <p>The key to look for.</p>
mixed $fallback <p>Value to fallback to.</p>
array|null $array <p>The array to get from, if it's set to "null" we use the current array from the class.</p>
bool $useByReference
Return:
mixed|static
↑alias: for "Arrayy->toArray()"
Parameters:nothing
Return:
array
↑Get the current array from the "Arrayy"-object.
alias for "toArray()"
Parameters:
- `bool $convertAllArrayyElements
Convert all Child-"Arrayy" objects also to arrays.
e.g.: A generator maybe return the same key more than once,so maybe you will ignore the keys.
`Return:
array
↑Creates a copy of the ArrayyObject.
Parameters:nothing
Return:
array
↑Get the current array from the "Arrayy"-object as generator.
Parameters:nothing
Return:
\Generator
↑Returns the values from a single column of the input array, identified bythe $columnKey, can be used to extract data-columns from multi-arrays.
EXAMPLE:a([['foo' => 'bar', 'id' => 1], ['foo => 'lall', 'id' => 2]])->getColumn('foo', 'id'); // Arrayy[1 => 'bar', 2 => 'lall']
INFO: Optionally, you may provide an $indexKey to index the values in the returnedarray by the values from the $indexKey column in the input array.
Parameters:
int|string|null $columnKey
int|string|null $indexKey
Return:
static <p>(Immutable)</p>
Parameters:nothing
Return:
TODO: __not_detected__
↑Get the current array from the "Arrayy"-object as generator.
Parameters:nothing
Return:
\Generator
↑Get the current array from the "Arrayy"-object as generator by reference.
Parameters:nothing
Return:
\Generator
↑Returns a new iterator, thus implementing the \Iterator interface.
EXAMPLE:a(['foo', 'bar'])->getIterator(); // ArrayyIterator['foo', 'bar']
Parameters:nothing
Return:
\Iterator<mixed,mixed> <p>An iterator for the values in the array.</p>
↑Gets the iterator classname for the ArrayObject.
Parameters:nothing
Return:
string
↑alias: for "Arrayy->keys()"
Parameters:nothing
Return:
static <p>(Immutable)</p>
↑Get the current array from the "Arrayy"-object as list.
alias for "toList()"
Parameters:
- `bool $convertAllArrayyElements
Convert all Child-"Arrayy" objects also to arrays.
Return:
array
↑Get the current array from the "Arrayy"-object as object.
Parameters:nothing
Return:
\stdClass
getPhpDocPropertiesFromClass(): array<array-key,\TypeCheckInterface>|\TypeCheckArray<array-key,\TypeCheckInterface>
Parameters:nothing
Return:
array<array-key,\TypeCheckInterface>|\TypeCheckArray<array-key,\TypeCheckInterface>
↑alias: for "Arrayy->randomImmutable()"
Parameters:nothing
Return:
static <p>(Immutable)</p>
↑alias: for "Arrayy->randomKey()"
Parameters:nothing
Return:
mixed|null <p>Get a key/index or null if there wasn't a key/index.</p>
↑alias: for "Arrayy->randomKeys()"
Parameters:
int $number
Return:
static <p>(Immutable)</p>
↑alias: for "Arrayy->randomValue()"
Parameters:nothing
Return:
mixed|null <p>Get a random value or null if there wasn't a value.</p>
↑alias: for "Arrayy->randomValues()"
Parameters:
int $number
Return:
static <p>(Immutable)</p>
↑Gets all values.
Parameters:nothing
Return:
static <p>The values of all elements in this array, in the order they appear in the array.</p>
↑Gets all values via Generator.
Parameters:nothing
Return:
\Generator <p>The values of all elements in this array, in the order they appear in the array as Generator.</p>
↑Group values from a array according to the results of a closure.
Parameters:
\Closure(T , TKey ): TKey|TKey $grouper <p>A callable function name.</p>
bool $saveKeys
Return:
static <p>(Immutable)</p>
↑Check if an array has a given key.
Parameters:
null|TKey|TKey[] $key
Return:
bool
↑Check if an array has a given value.
INFO: If you need to search recursive please usecontains($value, true)
.
Parameters:
T $value
Return:
bool
↑Implodes the values of this array.
EXAMPLE:a([0 => -9, 1, 2])->implode('|'); // '-9|1|2'
Parameters:
string $glue
string $prefix
Return:
string
↑Implodes the keys of this array.
Parameters:
string $glue
Return:
string
↑Given a list and an iterate-function that returnsa key for each element in the list (or a property name),returns an object with an index of each item.
Parameters:
array- $key
Return:
static <p>(Immutable)</p>
↑alias: for "Arrayy->searchIndex()"
Parameters:
T $value <p>The value to search for.</p>
Return:
false|int|string
↑Get everything but the last..$to items.
EXAMPLE:a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->initial(2); // Arrayy[0 => 'foo']
Parameters:
int $to
Return:
static <p>(Immutable)</p>
↑Return an array with all elements found in input array.
EXAMPLE:a(['foo', 'bar'])->intersection(['bar', 'baz']); // Arrayy['bar']
Parameters:
array<TKey, T> $search
bool $keepKeys
Return:
static <p>(Immutable)</p>
↑Return an array with all elements found in input array.
Parameters:
array ...$array
Return:
static <p>(Immutable)</p>
↑Return a boolean flag which indicates whether the two input arrays have any common elements.
EXAMPLE:a(['foo', 'bar'])->intersects(['föö', 'bär']); // false
Parameters:
array<TKey, T> $search
Return:
bool
↑Invoke a function on all of an array's values.
Parameters:
callable $callable
mixed $arguments
Return:
static <p>(Immutable)</p>
↑Check whether array is associative or not.
EXAMPLE:a(['foo' => 'bar', 2, 3])->isAssoc(); // true
Parameters:
bool $recursive
Return:
bool <p>Returns true if associative, false otherwise.</p>
↑Check if a given key or keys are empty.
Parameters:
int|int[]|string|string[]|null $keys
Return:
bool <p>Returns true if empty, false otherwise.</p>
↑Check if the current array is equal to the given "$array" or not.
EXAMPLE:a(['💩'])->isEqual(['💩']); // true
Parameters:
array $array
Return:
bool
↑Check if the current array is a multi-array.
EXAMPLE:a(['foo' => [1, 2 , 3]])->isMultiArray(); // true
Parameters:nothing
Return:
bool
↑Check whether array is numeric or not.
Parameters:nothing
Return:
bool <p>Returns true if numeric, false otherwise.</p>
↑Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not.
EXAMPLE:a([0 => 'foo', 1 => 'lall', 2 => 'foobar'])->isSequential(); // true
INFO: If the array is empty we count it as non-sequential.
Parameters:
bool $recursive
Return:
bool
Parameters:nothing
Return:
array
↑Gets the key/index of the element at the current internal iterator position.
Parameters:nothing
Return:
int|string|null
↑Checks if the given key exists in the provided array.
INFO: This method only use "array_key_exists()" if you want to use "dot"-notation,then you need to use "Arrayy->offsetExists()".
Parameters:
int|string $key the key to look for
Return:
bool
↑Get all keys from the current array.
EXAMPLE:a([1 => 'foo', 2 => 'foo2', 3 => 'bar'])->keys(); // Arrayy[1, 2, 3]
Parameters:
- `bool $recursive [optional]
Get all keys, also from all sub-arrays from an multi-dimensional array.
If specified, then only keys containing these values are returned.
`- `bool $strict [optional]Determines if strict comparison (===) should be used during the search.
`Return:
static <p>(Immutable) An array of all the keys in input.</p>
↑Sort an array by key in reverse order.
Parameters:
- `int $sort_flags [optional]
You may modify the behavior of the sort using the optionalparameter sort_flags, for detailssee sort.
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Sort an array by key in reverse order.
Parameters:
- `int $sort_flags [optional]
You may modify the behavior of the sort using the optionalparameter sort_flags, for detailssee sort.
Return:
$this <p>(Immutable)</p>
↑Sort the entries by key.
Parameters:
- `int $sort_flags [optional]
You may modify the behavior of the sort using the optionalparameter sort_flags, for detailssee sort.
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Sort the entries by key.
Parameters:
- `int $sort_flags [optional]
You may modify the behavior of the sort using the optionalparameter sort_flags, for detailssee sort.
Return:
$this <p>(Immutable) Return this Arrayy object.</p>
↑Get the last value from the current array.
EXAMPLE:a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->last(); // 'lall'
Parameters:nothing
Return:
mixed|null <p>Return null if there wasn't a element.</p>
↑Get the last key from the current array.
Parameters:nothing
Return:
mixed|null <p>Return null if there wasn't a element.</p>
↑Get the last value(s) from the current array.
EXAMPLE:a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->lasts(2); // Arrayy[0 => 'bar', 1 => 'lall']
Parameters:
int|null $number
Return:
static <p>(Immutable)</p>
↑Get the last value(s) from the current array.
EXAMPLE:a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->lasts(2); // Arrayy[0 => 'bar', 1 => 'lall']
Parameters:
int|null $number
Return:
$this <p>(Mutable)</p>
↑Count the values from the current array.
alias: for "Arrayy->count()"
Parameters:
int $mode
Return:
int
↑Apply the given function to the every element of the array,collecting the results.
EXAMPLE:a(['foo', 'Foo'])->map('mb_strtoupper'); // Arrayy['FOO', 'FOO']
Parameters:
callable $callable
bool $useKeyAsSecondParameter
mixed ...$arguments
Return:
static <p>(Immutable) Arrayy object with modified elements.</p>
↑Check if all items in current array match a truth test.
EXAMPLE:$closure = function ($value, $key) {return ($value % 2 === 0);};a([2, 4, 8])->matches($closure); // true
Parameters:
\Closure(T , TKey ): bool $closure
Return:
bool
↑Check if any item in the current array matches a truth test.
EXAMPLE:$closure = function ($value, $key) {return ($value % 2 === 0);};a([1, 4, 7])->matches($closure); // true
Parameters:
\Closure(T , TKey ): bool $closure
Return:
bool
↑Get the max value from an array.
EXAMPLE:a([-9, -8, -7, 1.32])->max(); // 1.32
Parameters:nothing
Return:
false|float|int|string <p>Will return false if there are no values.</p>
↑Merge the new $array into the current array.
- keep key,value from the current array, also if the index is in the new $array
EXAMPLE:$array1 = [1 => 'one', 'foo' => 'bar1'];$array2 = ['foo' => 'bar2', 3 => 'three'];a($array1)->mergeAppendKeepIndex($array2); // Arrayy[1 => 'one', 'foo' => 'bar2', 3 => 'three']// ---$array1 = [0 => 'one', 1 => 'foo'];$array2 = [0 => 'foo', 1 => 'bar2'];a($array1)->mergeAppendKeepIndex($array2); // Arrayy[0 => 'foo', 1 => 'bar2']
Parameters:
array $array
bool $recursive
Return:
static <p>(Immutable)</p>
↑Merge the new $array into the current array.
- replace duplicate assoc-keys from the current array with the key,values from the new $array
- create new indexes
EXAMPLE:$array1 = [1 => 'one', 'foo' => 'bar1'];$array2 = ['foo' => 'bar2', 3 => 'three'];a($array1)->mergeAppendNewIndex($array2); // Arrayy[0 => 'one', 'foo' => 'bar2', 1 => 'three']// ---$array1 = [0 => 'one', 1 => 'foo'];$array2 = [0 => 'foo', 1 => 'bar2'];a($array1)->mergeAppendNewIndex($array2); // Arrayy[0 => 'one', 1 => 'foo', 2 => 'foo', 3 => 'bar2']
Parameters:
array $array
bool $recursive
Return:
static <p>(Immutable)</p>
↑Merge the the current array into the $array.
- use key,value from the new $array, also if the index is in the current array
EXAMPLE:$array1 = [1 => 'one', 'foo' => 'bar1'];$array2 = ['foo' => 'bar2', 3 => 'three'];a($array1)->mergePrependKeepIndex($array2); // Arrayy['foo' => 'bar1', 3 => 'three', 1 => 'one']// ---$array1 = [0 => 'one', 1 => 'foo'];$array2 = [0 => 'foo', 1 => 'bar2'];a($array1)->mergePrependKeepIndex($array2); // Arrayy[0 => 'one', 1 => 'foo']
Parameters:
array $array
bool $recursive
Return:
static <p>(Immutable)</p>
↑Merge the current array into the new $array.
- replace duplicate assoc-keys from new $array with the key,values from the current array
- create new indexes
EXAMPLE:$array1 = [1 => 'one', 'foo' => 'bar1'];$array2 = ['foo' => 'bar2', 3 => 'three'];a($array1)->mergePrependNewIndex($array2); // Arrayy['foo' => 'bar1', 0 => 'three', 1 => 'one']// ---$array1 = [0 => 'one', 1 => 'foo'];$array2 = [0 => 'foo', 1 => 'bar2'];a($array1)->mergePrependNewIndex($array2); // Arrayy[0 => 'foo', 1 => 'bar2', 2 => 'one', 3 => 'foo']
Parameters:
array $array
bool $recursive
Return:
static <p>(Immutable)</p>
Parameters:nothing
Return:
\ArrayyMeta|mixed|static
↑Get the min value from an array.
EXAMPLE:a([-9, -8, -7, 1.32])->min(); // -9
Parameters:nothing
Return:
false|mixed <p>Will return false if there are no values.</p>
↑Get the most used value from the array.
Parameters:nothing
Return:
mixed|null <p>(Immutable) Return null if there wasn't an element.</p>
↑Get the most used value from the array.
Parameters:
int|null $number <p>How many values you will take?</p>
Return:
static <p>(Immutable)</p>
↑Move an array element to a new index.
EXAMPLE:$arr2 = new A(['A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e']);$newArr2 = $arr2->moveElement('D', 1); // Arrayy['A' => 'a', 'D' => 'd', 'B' => 'b', 'C' => 'c', 'E' => 'e']
Parameters:
int|string $from
int $to
Return:
static <p>(Immutable)</p>
↑Move an array element to the first place.
INFO: Instead of "Arrayy->moveElement()" this method will NOTloss the keys of an indexed array.
Parameters:
int|string $key
Return:
static <p>(Immutable)</p>
↑Move an array element to the last place.
INFO: Instead of "Arrayy->moveElement()" this method will NOTloss the keys of an indexed array.
Parameters:
int|string $key
Return:
static <p>(Immutable)</p>
↑Sort an array using a case insensitive "natural order" algorithm.
Parameters:nothing
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Sort an array using a case insensitive "natural order" algorithm.
Parameters:nothing
Return:
$this <p>(Immutable) Return this Arrayy object.</p>
↑Sort entries using a "natural order" algorithm.
Parameters:nothing
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Sort entries using a "natural order" algorithm.
Parameters:nothing
Return:
$this <p>(Immutable) Return this Arrayy object.</p>
↑Moves the internal iterator position to the next element and returns this element.
Parameters:nothing
Return:
false|mixed <p>(Mutable) Will return false if there are no values.</p>
↑Get the next nth keys and values from the array.
Parameters:
int $step
int $offset
Return:
static <p>(Immutable)</p>
↑Whether or not an offset exists.
Parameters:
bool|int|string $offset
Return:
bool
↑Returns the value at specified offset.
Parameters:
TKey $offset
Return:
mixed <p>Will return null if the offset did not exists.</p>
↑Assigns a value to the specified offset + check the type.
Parameters:
int|string|null $offset
mixed $value
Return:
void
↑Unset an offset.
Parameters:
int|string $offset
Return:
void <p>(Mutable) Return nothing.</p>
↑Get a subset of the items from the given array.
Parameters:
array-key[] $keys
Return:
static <p>(Immutable)</p>
↑Pad array to the specified size with a given value.
Parameters:
int $size <p>Size of the result array.</p>
mixed $value <p>Empty value by default.</p>
Return:
static <p>(Immutable) Arrayy object padded to $size with $value.</p>
↑Partitions this array in two array according to a predicate.
Keys are preserved in the resulting array.
Parameters:
\Closure(T , TKey ): bool $closure <p>The predicate on which to partition.</p>
Return:
array<int,static> <p>An array with two elements. The first element contains the array of elements where the predicate returned TRUE, the second element contains the array of elements where the predicate returned FALSE.</p>
↑Pop a specified value off the end of the current array.
Parameters:nothing
Return:
mixed|null <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p>
↑Prepend a (key) + value to the current array.
EXAMPLE:a(['fòô' => 'bàř'])->prepend('foo'); // Arrayy[0 => 'foo', 'fòô' => 'bàř']
Parameters:
T $value
TKey|null $key
Return:
$this <p>(Mutable) Return this Arrayy object, with the prepended value.</p>
↑Prepend a (key) + value to the current array.
EXAMPLE:a(['fòô' => 'bàř'])->prependImmutable('foo')->getArray(); // [0 => 'foo', 'fòô' => 'bàř']
Parameters:
T $value
TKey $key
Return:
$this <p>(Immutable) Return this Arrayy object, with the prepended value.</p>
↑Add a suffix to each key.
Parameters:
float|int|string $suffix
Return:
static <p>(Immutable) Return an Arrayy object, with the prepended keys.</p>
↑Add a suffix to each value.
Parameters:
float|int|string $suffix
Return:
static <p>(Immutable) Return an Arrayy object, with the prepended values.</p>
↑Return the value of a given key anddelete the key.
Parameters:
int|int[]|string|string[]|null $keyOrKeys
TFallback $fallback
Return:
mixed
↑Push one or more values onto the end of array at once.
Parameters:
array<TKey, T> ...$args
Return:
$this <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p>
↑Get a random value from the current array.
EXAMPLE:a([1, 2, 3, 4])->randomImmutable(2); // e.g.: Arrayy[1, 4]
Parameters:
int|null $number <p>How many values you will take?</p>
Return:
static <p>(Immutable)</p>
↑Pick a random key/index from the keys of this array.
EXAMPLE:$arrayy = A::create([1 => 'one', 2 => 'two']);$arrayy->randomKey(); // e.g. 2
Parameters:nothing
Return:
mixed|null <p>Get a key/index or null if there wasn't a key/index.</p>
↑Pick a given number of random keys/indexes out of this array.
EXAMPLE:a([1 => 'one', 2 => 'two'])->randomKeys(); // e.g. Arrayy[1, 2]
Parameters:
int $number <p>The number of keys/indexes (should be <= \count($this->array))</p>
Return:
static <p>(Immutable)</p>
↑Get a random value from the current array.
EXAMPLE:a([1, 2, 3, 4])->randomMutable(2); // e.g.: Arrayy[1, 4]
Parameters:
int|null $number <p>How many values you will take?</p>
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Pick a random value from the values of this array.
EXAMPLE:a([1 => 'one', 2 => 'two'])->randomValue(); // e.g. 'one'
Parameters:nothing
Return:
mixed <p>Get a random value or null if there wasn't a value.</p>
↑Pick a given number of random values out of this array.
EXAMPLE:a([1 => 'one', 2 => 'two'])->randomValues(); // e.g. Arrayy['one', 'two']
Parameters:
int $number
Return:
static <p>(Mutable)</p>
Parameters:
array $array
int $number
Return:
self
↑Reduce the current array via callable e.g. anonymous-function and return the end result.
EXAMPLE:a([1, 2, 3, 4])->reduce(function ($carry, $item) {return $carry * $item;},1); // Arrayy[24]
Parameters:
callable $callable
T2 $initial
Return:
static <p>(Immutable)</p>
Parameters:
bool $unique
Return:
static <p>(Immutable)</p>
↑Create a numerically re-indexed Arrayy object.
EXAMPLE:a([2 => 1, 3 => 2])->reindex(); // Arrayy[0 => 1, 1 => 2]
Parameters:nothing
Return:
$this <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p>
↑Return all items that fail the truth test.
EXAMPLE:$closure = function ($value) {return $value % 2 !== 0;}a([1, 2, 3, 4])->reject($closure); // Arrayy[1 => 2, 3 => 4]
Parameters:
\Closure(T , TKey ): bool $closure
Return:
static <p>(Immutable)</p>
↑Remove a value from the current array (optional using dot-notation).
EXAMPLE:a([1 => 'bar', 'foo' => 'foo'])->remove(1); // Arrayy['foo' => 'foo']
Parameters:
TKey|TKey[] $key
Return:
static <p>(Mutable)</p>
↑alias: for "Arrayy->removeValue()"
Parameters:
T $element
Return:
static <p>(Immutable)</p>
↑Remove the first value from the current array.
EXAMPLE:a([1 => 'bar', 'foo' => 'foo'])->removeFirst(); // Arrayy['foo' => 'foo']
Parameters:nothing
Return:
static <p>(Immutable)</p>
↑Remove the last value from the current array.
EXAMPLE:a([1 => 'bar', 'foo' => 'foo'])->removeLast(); // Arrayy[1 => 'bar']
Parameters:nothing
Return:
static <p>(Immutable)</p>
↑Removes a particular value from an array (numeric or associative).
EXAMPLE:a([1 => 'bar', 'foo' => 'foo'])->removeValue('foo'); // Arrayy[1 => 'bar']
Parameters:
T $value
Return:
static <p>(Immutable)</p>
↑Generate array of repeated arrays.
Parameters:
int $times <p>How many times has to be repeated.</p>
Return:
static <p>(Immutable)</p>
↑Replace a key with a new key/value pair.
EXAMPLE:$arrayy = a([1 => 'foo', 2 => 'foo2', 3 => 'bar']);$arrayy->replace(2, 'notfoo', 'notbar'); // Arrayy[1 => 'foo', 'notfoo' => 'notbar', 3 => 'bar']
Parameters:
TKey $oldKey
TKey $newKey
T $newValue
Return:
static <p>(Immutable)</p>
↑Create an array using the current array as values and the other array as keys.
EXAMPLE:$firstArray = [1 => 'one',2 => 'two',3 => 'three',];$secondArray = ['one' => 1,1 => 'one',2 => 2,];$arrayy = a($firstArray);$arrayy->replaceAllKeys($secondArray); // Arrayy[1 => "one", 'one' => "two", 2 => "three"]
Parameters:
array<TKey> $keys <p>An array of keys.</p>
Return:
- `static
(Immutable) Arrayy object with keys from the other array, empty Arrayy object if the number of elementsfor each array isn't equal or if the arrays are empty.
↑Create an array using the current array as keys and the other array as values.
EXAMPLE:$firstArray = [1 => 'one',2 => 'two',3 => 'three',];$secondArray = ['one' => 1,1 => 'one',2 => 2,];$arrayy = a($firstArray);$arrayy->replaceAllValues($secondArray); // Arrayy['one' => 1, 'two' => 'one', 'three' => 2]
Parameters:
array $array <p>An array of values.</p>
Return:
- `static
(Immutable) Arrayy object with values from the other array, empty Arrayy object if the number of elementsfor each array isn't equal or if the arrays are empty.
↑Replace the keys in an array with another set.
EXAMPLE:a([1 => 'bar', 'foo' => 'foo'])->replaceKeys([1 => 2, 'foo' => 'replaced']); // Arrayy[2 => 'bar', 'replaced' => 'foo']
Parameters:
array<TKey> $keys <p>An array of keys matching the array's size.</p>
Return:
static <p>(Immutable)</p>
↑Replace the first matched value in an array.
EXAMPLE:$testArray = ['bar', 'foo' => 'foo', 'foobar' => 'foobar'];a($testArray)->replaceOneValue('foo', 'replaced'); // Arrayy['bar', 'foo' => 'replaced', 'foobar' => 'foobar']
Parameters:
T $search <p>The value to replace.</p>
T $replacement <p>The value to replace.</p>
Return:
static <p>(Immutable)</p>
↑Replace values in the current array.
EXAMPLE:$testArray = ['bar', 'foo' => 'foo', 'foobar' => 'foobar'];a($testArray)->replaceValues('foo', 'replaced'); // Arrayy['bar', 'foo' => 'replaced', 'foobar' => 'replacedbar']
Parameters:
string $search <p>The value to replace.</p>
string $replacement <p>What to replace it with.</p>
Return:
static <p>(Immutable)</p>
↑Get the last elements from index $from until the end of this array.
EXAMPLE:a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->rest(2); // Arrayy[0 => 'lall']
Parameters:
int $from
Return:
static <p>(Immutable)</p>
↑Return the array in the reverse order.
EXAMPLE:a([1 => 1, 2 => 2, 3 => 3])->reverse(); // self[3, 2, 1]
Parameters:nothing
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Return the array with keys in the reverse order.
EXAMPLE:a([1 => 1, 2 => 2, 3 => 3])->reverse(); // self[3 => 3, 2 => 2, 1 => 1]
Parameters:nothing
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Sort an array in reverse order.
Parameters:
- `int $sort_flags [optional]
You may modify the behavior of the sort using the optionalparameter sort_flags, for detailssee sort.
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Sort an array in reverse order.
Parameters:
- `int $sort_flags [optional]
You may modify the behavior of the sort using the optionalparameter sort_flags, for detailssee sort.
Return:
$this <p>(Immutable) Return this Arrayy object.</p>
↑Search for the first index of the current array via $value.
EXAMPLE:a(['fòô' => 'bàř', 'lall' => 'bàř'])->searchIndex('bàř'); // Arrayy[0 => 'fòô']
Parameters:
T $value
Return:
false|int|string <p>Will return <b>FALSE</b> if the value can't be found.</p>
↑Search for the value of the current array via $index.
EXAMPLE:a(['fòô' => 'bàř'])->searchValue('fòô'); // Arrayy[0 => 'bàř']
Parameters:
TKey $index
Return:
static <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p>
↑Serialize the current "Arrayy"-object.
EXAMPLE:a([1, 4, 7])->serialize();
Parameters:nothing
Return:
string
↑Set a value for the current array (optional using dot-notation).
EXAMPLE:$arrayy = a(['Lars' => ['lastname' => 'Moelleken']]);$arrayy->set('Lars.lastname', 'Müller'); // Arrayy['Lars', ['lastname' => 'Müller']]]
Parameters:
TKey $key <p>The key to set.</p>
T $value <p>Its value.</p>
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Get a value from a array and set it if it was not.
WARNING: this method only set the value, if the $key is not already set
EXAMPLE:$arrayy = a([1 => 1, 2 => 2, 3 => 3]);$arrayy->setAndGet(1, 4); // 1$arrayy->setAndGet(0, 4); // 4
Parameters:
TKey $key <p>The key</p>
T $fallback <p>The default value to set if it isn't.</p>
Return:
mixed <p>(Mutable)</p>
Parameters:
int $flags
Return:
TODO: __not_detected__
↑Sets the iterator classname for the current "Arrayy"-object.
Parameters:
class-string<\Arrayy\ArrayyIterator> $iteratorClass
Return:
void
↑Shifts a specified value off the beginning of array.
Parameters:nothing
Return:
mixed|null <p>(Mutable) A shifted element from the current array.</p>
↑Shuffle the current array.
EXAMPLE:a([1 => 'bar', 'foo' => 'foo'])->shuffle(); // e.g.: Arrayy[['foo' => 'foo', 1 => 'bar']]
Parameters:
bool $secure <p>using a CSPRNG | @see https://paragonie.com/b/JvICXzh_jhLyt4y3</p>
array|null $array [optional]
Return:
static <p>(Immutable)</p>
↑Count the values from the current array.
alias: for "Arrayy->count()"
Parameters:
int $mode
Return:
int
↑Checks whether array has exactly $size items.
Parameters:
int $size
Return:
bool
↑Checks whether array has between $fromSize to $toSize items. $toSize can besmaller than $fromSize.
Parameters:
int $fromSize
int $toSize
Return:
bool
↑Checks whether array has more than $size items.
Parameters:
int $size
Return:
bool
↑Checks whether array has less than $size items.
Parameters:
int $size
Return:
bool
↑Counts all elements in an array, or something in an object.
For objects, if you have SPL installed, you can hook into count() by implementing interface {@see \Countable}.The interface has exactly one method, {@see \Countable::count()}, which returns the return value for the count()function. Please see the {@see \Array} section of the manual for a detailed explanation of how arrays areimplemented and used in PHP.
Parameters:nothing
Return:
- `int
The number of elements in var, which istypically an array, since anything else will have oneelement.
If var is not an array or an object withimplemented Countable interface,1 will be returned.There is one exception, if var is &null;,0 will be returned.
Caution: count may return 0 for a variable that isn't set,but it may also return 0 for a variable that has been initialized with anempty array. Use isset to test if a variable is set.
`↑Extract a slice of the array.
Parameters:
int $offset <p>Slice begin index.</p>
int|null $length <p>Length of the slice.</p>
bool $preserveKeys <p>Whether array keys are preserved or no.</p>
Return:
static <p>(Immutable) A slice of the original array with length $length.</p>
↑Sort the current array and optional you can keep the keys.
EXAMPLE:a(3 => 'd', 2 => 'f', 0 => 'a')->sort(SORT_ASC, SORT_NATURAL, false); // Arrayy[0 => 'a', 1 => 'd', 2 => 'f']
Parameters:
int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p>
int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or <strong>SORT_NATURAL</strong></p>
bool $keepKeys
Return:
static <p>(Mutable) Return this Arrayy object.</p>
↑Sort the current array and optional you can keep the keys.
Parameters:
int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p>
int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or <strong>SORT_NATURAL</strong></p>
bool $keepKeys
Return:
static <p>(Immutable) Return this Arrayy object.</p>
↑Sort the current array by key.
EXAMPLE:a([1 => 2, 0 => 1])->sortKeys(\SORT_ASC); // Arrayy[0 => 1, 1 => 2]
Parameters:
int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p>
int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or <strong>SORT_NATURAL</strong></p>
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Sort the current array by key.
Parameters:
int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p>
int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or <strong>SORT_NATURAL</strong></p>
Return:
$this <p>(Immutable) Return this Arrayy object.</p>
↑Sort the current array by value.
EXAMPLE:a(3 => 'd', 2 => 'f', 0 => 'a')->sortValueKeepIndex(SORT_ASC, SORT_REGULAR); // Arrayy[0 => 'a', 3 => 'd', 2 => 'f']
Parameters:
int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p>
int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or <strong>SORT_NATURAL</strong></p>
Return:
static <p>(Mutable)</p>
↑Sort the current array by value.
EXAMPLE:a(3 => 'd', 2 => 'f', 0 => 'a')->sortValueNewIndex(SORT_ASC, SORT_NATURAL); // Arrayy[0 => 'a', 1 => 'd', 2 => 'f']
Parameters:
int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p>
int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or <strong>SORT_NATURAL</strong></p>
Return:
static <p>(Mutable)</p>
↑Sort a array by value or by a closure.
- If the sorter is null, the array is sorted naturally.
- Associative (string) keys will be maintained, but numeric keys will be re-indexed.
EXAMPLE:$testArray = range(1, 5);$under = a($testArray)->sorter(function ($value) {return $value % 2 === 0;});var_dump($under); // Arrayy[1, 3, 5, 2, 4]
Parameters:
callable|mixed|null $sorter
int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p>
int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or <strong>SORT_NATURAL</strong></p>
Return:
static <p>(Immutable)</p>
Parameters:
int $offset
int|null $length
array<T> $replacement
Return:
static <p>(Immutable)</p>
↑Split an array in the given amount of pieces.
EXAMPLE:a(['a' => 1, 'b' => 2])->split(2, true); // Arrayy[['a' => 1], ['b' => 2]]
Parameters:
int $numberOfPieces
bool $keepKeys
Return:
static <p>(Immutable)</p>
↑Strip all empty items from the current array.
EXAMPLE:a(['a' => 1, 'b' => ''])->stripEmpty(); // Arrayy[['a' => 1]]
Parameters:nothing
Return:
static <p>(Immutable)</p>
↑Swap two values between positions by key.
EXAMPLE:a(['a' => 1, 'b' => ''])->swap('a', 'b'); // Arrayy[['a' => '', 'b' => 1]]
Parameters:
int|string $swapA <p>a key in the array</p>
int|string $swapB <p>a key in the array</p>
Return:
static <p>(Immutable)</p>
↑Get the current array from the "Arrayy"-object.
alias for "getArray()"
Parameters:
- `bool $convertAllArrayyElements
Convert all Child-"Arrayy" objects also to arrays.
e.g.: A generator maybe return the same key more than once,so maybe you will ignore the keys.
`Return:
array
↑Convert the current array to JSON.
EXAMPLE:a(['bar', ['foo']])->toJson(); // '["bar",{"1":"foo"}]'
Parameters:
int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p>
int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p>
Return:
string
↑Get the current array from the "Arrayy"-object as list.
Parameters:
- `bool $convertAllArrayyElements
Convert all Child-"Arrayy" objects also to arrays.
Return:
array
Parameters:
string[]|null $items [optional]
string[] $helper [optional]
Return:
static|static[]
↑Implodes array to a string with specified separator.
Parameters:
string $separator [optional] <p>The element's separator.</p>
Return:
string <p>The string representation of array, separated by ",".</p>
↑Sort the entries with a user-defined comparison function and maintain key association.
Parameters:
callable $callable
Return:
$this <p>(Mutable) Return this Arrayy object.</p>
↑Sort the entries with a user-defined comparison function and maintain key association.
Parameters:
callable $callable
Return:
$this <p>(Immutable) Return this Arrayy object.</p>
↑Sort the entries by keys using a user-defined comparison function.
Parameters:
callable $callable
Return:
static <p>(Mutable) Return this Arrayy object.</p>
↑Sort the entries by keys using a user-defined comparison function.
Parameters:
callable $callable
Return:
static <p>(Immutable) Return this Arrayy object.</p>
↑alias: for "Arrayy->uniqueNewIndex()"
Parameters:nothing
Return:
static <p>(Mutable) Return this Arrayy object, with the appended values.</p>
↑Return a duplicate free copy of the current array. (with the old keys)
EXAMPLE:a([2 => 1, 3 => 2, 4 => 2])->uniqueNewIndex(); // Arrayy[2 => 1, 3 => 2]
Parameters:nothing
Return:
$this <p>(Mutable)</p>
↑Return a duplicate free copy of the current array.
EXAMPLE:a([2 => 1, 3 => 2, 4 => 2])->uniqueNewIndex(); // Arrayy[1, 2]
Parameters:nothing
Return:
$this <p>(Mutable)</p>
↑Unserialize an string and return the instance of the "Arrayy"-class.
EXAMPLE:$serialized = a([1, 4, 7])->serialize();a()->unserialize($serialized);
Parameters:
string $string
Return:
$this
↑Prepends one or more values to the beginning of array at once.
Parameters:
array<TKey, T> ...$args
Return:
$this <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p>
↑Tests whether the given closure return something valid for all elements of this array.
Parameters:
\Closure(T , TKey ): bool $closure the predicate
Return:
bool <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p>
↑Get all values from a array.
EXAMPLE:$arrayy = a([1 => 'foo', 2 => 'foo2', 3 => 'bar']);$arrayyTmp->values(); // Arrayy[0 => 'foo', 1 => 'foo2', 2 => 'bar']
Parameters:nothing
Return:
static <p>(Immutable)</p>
↑Apply the given function to every element in the array, discarding the results.
EXAMPLE:$callable = function (&$value, $key) {$value = $key;};$arrayy = a([1, 2, 3]);$arrayy->walk($callable); // Arrayy[0, 1, 2]
Parameters:
callable $callable
bool $recursive [optional] <p>Whether array will be walked recursively or no</p>
- `mixed $userData [optional]
If the optional $userData parameter is supplied,it will be passed as the third parameter to the $callable.
Return:
$this <p>(Mutable) Return this Arrayy object, with modified elements.</p>
↑Returns a collection of matching items.
Parameters:
string $keyOrPropertyOrMethod <p>The property or method to evaluate.</p>
mixed $value <p>The value to match.</p>
Return:
static
append | asort | count | exchangeArray |
getArrayCopy | getFlags | getIterator | getIteratorClass |
ksort | natcasesort | natsort | offsetExists |
offsetGet | offsetSet | offsetUnset | serialize |
setFlags | setIteratorClass | uasort | uksort |
unserialize |
Parameters:
null|mixed $value
Return:
TODO: __not_detected__
Parameters:
int $flags
Return:
TODO: __not_detected__
Parameters:nothing
Return:
TODO: __not_detected__
Parameters:
array|object $array
Return:
TODO: __not_detected__
Parameters:nothing
Return:
TODO: __not_detected__
Parameters:nothing
Return:
TODO: __not_detected__
Parameters:nothing
Return:
TODO: __not_detected__
Parameters:nothing
Return:
TODO: __not_detected__
Parameters:
int $flags
Return:
TODO: __not_detected__
Parameters:nothing
Return:
TODO: __not_detected__
Parameters:nothing
Return:
TODO: __not_detected__
Parameters:
null|mixed $key
Return:
TODO: __not_detected__
Parameters:
null|mixed $key
Return:
TODO: __not_detected__
Parameters:
null|mixed $key
null|mixed $value
Return:
TODO: __not_detected__
Parameters:
null|mixed $key
Return:
TODO: __not_detected__
Parameters:nothing
Return:
TODO: __not_detected__
Parameters:
int $flags
Return:
TODO: __not_detected__
Parameters:
string $iteratorClass
Return:
TODO: __not_detected__
Parameters:
callable $callback
Return:
TODO: __not_detected__
Parameters:
callable $callback
Return:
TODO: __not_detected__
Parameters:
string $data
Return:
TODO: __not_detected__
For support and donations please visitGithub |Issues |PayPal |Patreon.
For status updates and release announcements please visitReleases |Twitter |Patreon.
For professional support please contactme.
- Thanks toGitHub (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
- Thanks toIntelliJ as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
- Thanks toTravis CI for being the most awesome, easiest continous integration tool out there!
- Thanks toStyleCI for the simple but powerfull code style check.
- Thanks toPHPStan &&Psalm for relly great Static analysis tools and for discover bugs in the code!
From the project directory, tests can be ran usingphpunit
Released under the MIT License - seeLICENSE.txt
for details.
About
🗃 Array manipulation library for PHP, called Arrayy!