PHPackages                             breier/extended-array - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. breier/extended-array

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

breier/extended-array
=====================

A class that extends PHP-SPL ArrayIterator and implements loads of functionalities from PHP plain array handling

2.2.1(8mo ago)0631GPL-3.0-or-laterPHPPHP ^7.3|^8.0CI failing

Since May 3Pushed 6d ago1 watchersCompare

[ Source](https://github.com/breier/extended-array)[ Packagist](https://packagist.org/packages/breier/extended-array)[ RSS](/packages/breier-extended-array/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (5)Used By (1)

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-from-arrayiterator)
- [Methods in ExtendedArrayBase](#methods-in-extendedarraybase)
- [Methods in ExtendedArray](#methods-in-extendedarray)

Methods from ArrayIterator
--------------------------

[](#methods-from-arrayiterator)

You can find all the methods and their documentation at [php.net/manual/class.arrayiterator](https://www.php.net/manual/en/class.arrayiterator.php).

 But here is a list of non-modified methods:MethodParametersReturnDescriptionappendmixed $valuenull`[*]` Append an element to the objectcountintThe amount of elementscurrentmixedGet the element under the cursorgetFlagsintGet behaviour flags of the ArrayIteratorkeymixedCurrent position element indexoffsetGetmixed $indexmixedGet element in given indexseekint $positionnullMoves the cursor to given positionserializestringApplies PHP serialization to the objectsetFlagsstring $flagsnullSet behaviour flags of the ArrayIteratorunserializestring $serializednullPopulates self using PHP unserializevalidboolValidate element in the current position*\* "append" is indirectly modified as it uses "offsetSet" internally*

Methods in ExtendedArrayBase
----------------------------

[](#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:MethodParametersReturnDescriptionasorttrueExtending method to support sub-objectselementmixed`[added]` Element is an alias for "current"endthis`[added]` Move the cursor to the endfirstthis`[added]` First is an alias for "rewind"getArrayCopyarrayExtending method to convert sub-objects to arrayisArrayObjectmixed $arraybool`[added][static]` Identifies usable classesjsonEncode\[int $options\[, int $depth\]\]string`[added]` JSON EncodeksorttrueExtending method to update position maplastthis`[added]` Last is an alias to "end"natcasesortthisExtending method to update position mapnatsortthisExtending method to update position mapnextthisExtending method to return $thisoffsetExistsmixed $indexboolExtending method to behave like "array\_key\_exists"offsetSetmixed $index, mixed $newvalnullExtending method to update position mapoffsetUnsetmixed $indexnullExtending method to update position mapprevthis`[added]` Move the cursor to previous elementrewindthisExtending method to return $thisuasortcallable $cmp\_functionthisExtending method to update position mapuksortcallable $cmp\_functionthisExtending method to update position mapMethods in ExtendedArray
------------------------

[](#methods-in-extendedarray)

### `arsort(): ExtendedArray`

[](#arsort-extendedarray)

Reverse sort by element.

 Code Example```
