Download the PHP package breier/extended-array without Composer
On this page you can find all versions of the php package breier/extended-array. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package extended-array
Extended Array
This library started from a discussion on whether it's intuitive or not to get the first element of an array using "reset()". Well I think it's not!
In order to handle arrays and its elements in a clean code manner (readable and maintainable) I developed this library. Please enjoy (use at your own risk XD).
Table of Contents:
- Methods from ArrayIterator
- Methods in ExtendedArrayBase
- Methods in ExtendedArray
Methods from ArrayIterator
You can find all the methods and their documentation at php.net/manual/class.arrayiterator.
But here is a list of non-modified methods:
| Method | Parameters | Return | Description | | ------------ | ------------------ | ------ | ----------- | | append | mixed $value | null | `[*]` Append an element to the object | count | | int | The amount of elements | current | | mixed | Get the element under the cursor | getFlags | | int | Get behaviour flags of the ArrayIterator | key | | mixed | Current position element index | offsetGet | mixed $index | mixed | Get element in given index | seek | int $position | null | Moves the cursor to given position | serialize | | string | Applies PHP serialization to the object | setFlags | string $flags | null | Set behaviour flags of the ArrayIterator | unserialize | string $serialized | null | Populates self using PHP unserialize | valid | | bool | Validate element in the current position _* "append" is indirectly modified as it uses "offsetSet" internally_Methods in ExtendedArrayBase
This is the abstract class that modifies the behaviour of ArrayIterator to improve its use as a clean Object Oriented Class.
- It accepts any of the following types as a parameter to be instantiated:
- (null, array, \SplFixedArray, \ArrayObject, \ArrayIterator);
- It sets the default flag to ARRAY_AS_PROPS;
- It converts all sub-arrays into sub-instances of its class;
- It uses an internal positioning system to help navigate through (next, prev, ...);
- It has a magic __toString method that returns JSON;
Here's the complete list of methods:
| Method | Parameters | Return | Description | | ------------- | ---------------------- | ------ | ----------- | | asort | | this | Extending method to support sub-objects | element | | mixed | `[added]` Element is an alias for "current" | end | | this | `[added]` Move the cursor to the end | first | | this | `[added]` First is an alias for "rewind" | getArrayCopy | | array | Extending method to convert sub-objects to array | isArrayObject | mixed $array | bool | `[added][static]` Identifies usable classes | jsonEncode |Methods in ExtendedArray
arsort(): ExtendedArray
Reverse sort by element.
Code Example
contains(mixed $needle[, bool $strict]): bool
Contains is similar to "in_array" with object support.
Code Example
diff($array2, ...$arrays): ExtendedArray
Diff is similar to "array_diff" with object support.
Code Example
explode(string $delimiter, string $string[, int $limit = PHP_INT_MAX]): ExtendedArray
[static]
Instantiate from exploding a string by delimiter
Code Example
fill(int $start, int $num, $value): ExtendedArray
[static]
Instantiate an array filled with value by num of times
Code Example
filter([callable $callback[, int $flag]]): ExtendedArray
A poly-fill for "array_filter".
Code Example
filterWithObjects([callable $callback[, int $flag]]): ExtendedArray
Extending filter to support objects.
Code Example
fromJSON(string $json[, int $depth]): ExtendedArray
[static]
Instantiate from a JSON string.
Code Example
isArray(mixed $element): bool
[static]
Validates any type of array.
Code Example
implode(string $glue = ''): string
Concatenate array values in a string separated by $glue
Code Example
keys(): ExtendedArray
Get this array keys (properties' names).
Code Example
krsort(): ExtendedArray
Reverse sort by keys.
Code Example
map(callable $callback[, array ...$params]): ExtendedArray
A poly-fill for "array_map".
Code Example
mapWithObjects(callable $callback[, array ...$params]): ExtendedArray
Extending map to support objects.
Code Example
offsetGetFirst(): mixed
Gets first element without moving the array cursor.
Code Example
offsetGetLast(): mixed
Gets last element without moving the array cursor.
Code Example
offsetGetPosition(int $position): mixed
Gets element in the given position without moving the array cursor.
Code Example
shuffle(): ExtendedArray
Shuffle elements randomly
Code Example
values(): ExtendedArray
Get values in a numbered key array
Code Example
All versions of extended-array with dependencies
ext-pdo Version *
ext-json Version *