hxss / array-object
1.8.0
2021-06-30 15:36 UTC
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
array
type arg in most cases; - All methods that accepted
array
args now acceptsarray|ArrayObject
; - All methods that had to return
array
now returnsArrayObject
;
Exceptions and differences with php api:
Not realized functions:
Functions with changed API:
ArrayObject::combine()
- static method;array_fill
&array_fill_keys
are 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_first
realized asArrayObject::firstKey()
;array_key_last
realized asArrayObject::lastKey()
;- All
array_merge*
functions merged intoArrayObject::merge()
method; ArrayObject::multisort()
saves sorted arrays only in passedArrayObject
values. Allarray
-type args will used in sorting as usual but wouldn't updated.array_rand
realized asArrayObject::randKeys()
;array_replace
&array_replace_recursive
are merged into staticArrayObject::replace()
where last optional argumenttrue
means 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_recursive
are merged into staticArrayObject::walk()
where last optional argumenttrue
means 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. Likepush
but returns self;ArrayObject::prepend()
- Prepend one or more elements to the beginning of an array. Likeunshift
but 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$other
array;ArrayObject::touch()
- returns the value at specified offset or init it with$default
value;ArrayObject::generator()
- generates new array by user generator;