Download the PHP package bocharsky-bw/arrayzy without Composer
On this page you can find all versions of the php package bocharsky-bw/arrayzy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bocharsky-bw/arrayzy
More information about bocharsky-bw/arrayzy
Files in bocharsky-bw/arrayzy
Package arrayzy
Short Description A native PHP arrays easy manipulation library in OOP way.
License MIT
Homepage https://github.com/bocharsky-bw/Arrayzy
Informations about the package arrayzy
Arrayzy
The wrapper for all PHP built-in array functions and easy, object-oriented array manipulation library. In short: Arrays on steroids.
ArrayImitator
This is the main class of this library. Each method, which associated with the corresponding native PHP function, keep its behavior. In other words: methods could creates a new array (leaving the original array unchanged), operates on the same array (returns the array itself and DOES NOT create a new instance) or return some result.
NOTE: If method creates a new array but you don't need the first array you operate on, you can override it manually:
NOTE: If method operates on the same array but you need to keep the first array you operate on as unchanged, you can clone it manually first:
Contents
- Requirements
- Installation
- Creation
- Usage
- Chaining
- Public method list
- add
- chunk
- clear
- combine
- contains
- containsKey
- count
- create
- createClone
- createFromJson
- createFromObject
- createFromString
- createWithRange
- current
- customSort
- customSortKeys
- debug
- diff
- each
- end
- except
- exists
- export
- filter
- find
- first
- flip
- getIterator
- getKeys
- getRandom
- getRandomKey
- getRandomKeys
- getRandomValues
- getValues
- indexOf
- intersect
- intersectAssoc
- intersectKey
- isAssoc
- isEmpty
- isNumeric
- key
- last
- map
- merge
- next
- offsetExists
- offsetGet
- offsetSet
- offsetUnset
- only
- pad
- pop
- previous
- push
- reduce
- reindex
- replace
- reset
- reverse
- search
- shift
- shuffle
- slice
- sort
- sortKeys
- toArray
- toJson
- toReadableString
- toString
- unique
- unshift
- walk
- Contribution
- Links
Requirements
- PHP
5.4
or higher - PHP
JSON
extension
Installation
The preferred way to install this package is to use Composer:
If you don't use Composer
- register this package in your autoloader manually
or download this library and require
the necessary files directly in your scripts:
Creation
Create a new empty array with the new
statement.
NOTE: Don't forget about namespaces. You can use namespace aliases for simplicity if you want:
Create a new array with default values, passed it to the constructor as an array:
Also, new objects can be created with one of the public static methods prefixed with 'create':
- create
- createFromJson
- createFromObject
- createFromString
- createWithRange
Usage
You can get access to the values like with the familiar PHP array syntax:
NOTE: The following methods and principles apply to the ArrayImitator
class.
In the examples provided below the ArrayImitator
aliased with A
.
Chaining
Methods may be chained for ease of use:
Converting
Easily convert instance array elements to a simple PHP array
, string
,
readable string
or JSON format:
- toArray
- toJson
- toReadableString
- toString
Debugging
- debug
- export
Public method list
add
Associated with
$a[] = 'new item'
.
chunk
Associated with array_chunk().
clear
Associated with
$a = []
.
combine
Associated with array_combine().
contains
Associated with in_array().
containsKey
Associated with array_key_exists().
count
Associated with count().
create
createClone
Creates a shallow copy of the array.
Keep in mind, that in PHP variables contain only references to the object, NOT the object itself:
So if you DO NOT want to modify the current array, you need to clone it manually first:
createFromJson
Associated with json_decode().
Creates an array by parsing a JSON string:
createFromObject
Creates an instance array from any object
that implemented \ArrayAccess
interface:
createFromString
Associated with explode().
Creates an array from a simple PHP string
with specified separator:
createWithRange
Associated with range().
Creates an array of a specified range:
current
Associated with current().
Position of the iterator.
customSort
Associated with usort().
customSortKeys
Associated with uksort().
debug
Associated with print_r().
diff
Associated with array_diff().
each
Associated with each().
end
Associated with end().
except
Based on array_diff_key().
Chunk of an array without given keys.
exists
A custom contains method where you can supply your own custom logic in any callable function.
export
Associated with var_export().
filter
Associated with array_filter().
find
A custom find method where you can supply your own custom logic in any callable function.
first
Alias of reset.
flip
Associated with array_flip().
getIterator
Creates an external Iterator. Check the iteratorAggregate documentation for more information.
getKeys
Associated with array_keys().
getRandom
Associated with array_rand().
getRandomKey
Associated with array_rand().
getRandomKeys
Associated with array_rand().
getRandomValues
Associated with array_rand().
getValues
Associated with array_values().
indexOf
Alias of search.
intersect
Associated with array_intersect().
intersectAssoc
Associated with array_intersect_assoc().
intersectKey
Associated with array_intersect_key().
isAssoc
Check whether all array keys are associative.
isEmpty
Check whether array is empty.
isNumeric
Check whether all array keys are numeric.
key
Associated with key().
last
Alias of end.
map
Associated with array_map().
merge
Associated with array_merge() / array_merge_recursive().
next
Associated with next().
offsetExists
Implemented for ArrayAccess interface.
offsetGet
Implemented for ArrayAccess interface.
offsetSet
Implemented for ArrayAccess interface.
offsetUnset
Implemented for ArrayAccess interface.
only
Based on array_intersect_key().
Chunk of an array with only given keys.
pad
Associated with array_pad().
pop
Associated with array_pop().
previous
Associated with prev().
push
Associated with array_push().
The
push()
method allows multiple arguments.
reduce
Associated with array_reduce().
reindex
Based on array_values().
replace
Associated with array_replace() / array_replace_recursive().
reset
Associated with reset().
reverse
Associated with array_reverse().
search
Associated with array_search().
shift
Associated with array_shift().
shuffle
Associated with shuffle().
slice
Associated with array_slice().
sort
sortKeys
toArray
Convert the array to a simple PHP array
type:
toJson
Associated with json_encode().
Creates a JSON string from the array:
toReadableString
Based on implode().
Converts instance array to a readable PHP string
:
toString
Associated with implode().
Converts instance array to a simple PHP string
:
unique
Associated with array_unique().
unshift
Associated with array_unshift().
Method
unshift()
allow multiple arguments.
walk
Associated with array_walk() / array_walk_recursive().
Contribution
Feel free to submit an Issue or create a Pull Request if you find a bug or just want to propose an improvement suggestion.
In order to propose a new feature the best way is to submit an Issue and discuss it first.
Links
Arrayzy was inspired by Doctrine ArrayCollection class and Stringy library.
Look at the Stringy if you are looking for a PHP string manipulation library in an OOP way.
Move UP
All versions of arrayzy with dependencies
ext-json Version *