hxss / array-object
Installs: 3 377
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
pkg:composer/hxss/array-object
Requires
- php: >=5.6.39
- zendframework/zend-eventmanager: ^3.2
README
The OOP interface for PHP array.
The class realize almost all php functions.
Basic principles of work:
- All php functions with
array_prefix are now class methods without the prefix in camel case(array_change_key_case -> ArrayObject::changeKeyCase()); - Class methods do not require
arraytype arg in most cases; - All methods that accepted
arrayargs now acceptsarray|ArrayObject; - All methods that had to return
arraynow returnsArrayObject;
Exceptions and differences with php api:
Not realized functions:
Functions with changed API:
ArrayObject::combine()- static method;array_fill&array_fill_keysare merged into staticArrayObject::fill()where second argument defines behavior;ArrayObject::range()- static method;- All
array_diff*functions merged intoArrayObject::diff()where userfunc always gets 4 args(key1, val1, key2, val2); ArrayObject::filter()always pass 2 args into userfunc: key and val;- All
array_intersect*functions merged intoArrayObject::intersect()where userfunc always gets 4 args(key1, val1, key2, val2); array_key_firstrealized asArrayObject::firstKey();array_key_lastrealized asArrayObject::lastKey();- All
array_merge*functions merged intoArrayObject::merge()method; ArrayObject::multisort()saves sorted arrays only in passedArrayObjectvalues. Allarray-type args will used in sorting as usual but wouldn't updated.array_randrealized asArrayObject::randKeys();array_replace&array_replace_recursiveare merged into staticArrayObject::replace()where last optional argumenttruemeans recursion;- All array sort functions merged into
ArrayObject::sort()with 3 new flags that can be combined with default flags(bitwise OR); array_walk&array_walk_recursiveare merged into staticArrayObject::walk()where last optional argumenttruemeans recursion;
New features:
ArrayObject::recursive()- recursively convert all sub-array inArrayObject;ArrayObject::items()- returns original array;ArrayObject::append()- append one or more elements onto the end of array. Likepushbut returns self;ArrayObject::prepend()- Prepend one or more elements to the beginning of an array. Likeunshiftbut returns self;ArrayObject::rand()- returns associated array with one or more random items of an array;ArrayObject::first()- returns first value of the array;ArrayObject::last()- returns last value of the array;ArrayObject::eq()- checks if the object equal to$otherarray;ArrayObject::touch()- returns the value at specified offset or init it with$defaultvalue;ArrayObject::generator()- generates new array by user generator;