Skip to content

Commit f28992f

Browse files
committed
Merge pull request bocharsky-bw#20 from JustusAdam/master
Improve and tweak the docs
2 parents 36e47e6 + a760068 commit f28992f

File tree

1 file changed

+56
-48
lines changed

1 file changed

+56
-48
lines changed

README.md

Lines changed: 56 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
# Arrayzy
22

3-
A native PHP arrays easy manipulation library in OOP way.
3+
The wrapper for all PHP built-in array functions and easy, object-oriented array manipulation library. In short: Arrays on steroids.
44

55
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/e0235f5d-a89b-4add-b3c6-45813d2bf9eb/mini.png)](https://insight.sensiolabs.com/projects/e0235f5d-a89b-4add-b3c6-45813d2bf9eb)
66
[![Build Status](https://travis-ci.org/bocharsky-bw/Arrayzy.svg?branch=master)](https://travis-ci.org/bocharsky-bw/Arrayzy)
77
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/bocharsky-bw/Arrayzy/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/bocharsky-bw/Arrayzy/?branch=master)
88
[![Code Coverage](https://scrutinizer-ci.com/g/bocharsky-bw/Arrayzy/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/bocharsky-bw/Arrayzy/?branch=master)
99

10-
There are two available classes with a different behaviour:
10+
There are two classes available with different behavior:
1111

1212
* [Arrayzy\MutableArray](#mutablearray)
1313
* [Arrayzy\ImmutableArray](#immutablearray)
1414

1515
## MutableArray
1616

17-
Each functional method operate on the same array and return the same instance
18-
(**DO NOT** create a new instance) except only few methods starts with `create` prefix.
19-
This way a bit improve performance and provide more convenience usage in OOP way.
17+
Each method operates on the same array and returns the array itself
18+
(it **DOES NOT** create a new instance), except methods starting with the
19+
`create` prefix. This way has slightly better performance and is more
20+
convenient to use in an OOP way.
2021

21-
> **NOTE:** Check the [CreateClone](#createclone) section if you want to operate on new instance NOT on same instance.
22+
> **NOTE:** Check the [CreateClone](#createclone) section if you want to operate on a new instance to preserve the current one.
2223
2324
## ImmutableArray
2425

25-
Each functional method operate on the same array but not modified it.
26-
Instead of this it return a new object (create a new instance).
27-
This way a bit disimprove performance but give you the behaviour
28-
seems like most of built-in PHP functions that returns a new array (**DO NOT** modified input one).
26+
Each method creates a new array, leaving the original array unchanged.
27+
This way has slightly worse performance but give you a behavior similar
28+
to most of the built-in PHP functions that return a new array.
2929

30-
> **NOTE:** If you don't need the first instance you operates on, you can override it manually:
30+
> **NOTE:** If you don't need the first array you operate on, you can override it manually:
3131
3232
``` php
3333
$a = ImmutableArray::create(['a', 'b', 'c']);
@@ -122,39 +122,41 @@ $ composer require bocharsky-bw/arrayzy:dev-master
122122
```
123123

124124
If you don't use `Composer` - register this package in your autoloader manually
125-
or download library manually and require the necessary files directly in your scripts:
125+
or download the library manually and `require` the necessary files directly in your scripts:
126126

127127
``` php
128128
require_once __DIR__ . '/path/to/library/src/MutableArray.php';
129129
```
130130

131-
Don't forget namespace. Use [namespace arbitrary alias][2] for simplicity if you want:
131+
Don't forget namespaces. Use [namespace aliases][2] for simplicity if you want:
132132

133133
``` php
134-
use Arrayzy\MutableArray as MuArr; //
135-
use Arrayzy\ImmutableArray as ImArr; // MuArr and ImArr is the arbitrary aliases
134+
use Arrayzy\MutableArray as MuArr;
135+
use Arrayzy\ImmutableArray as ImArr;
136136
```
137137

138138
## Creation
139139

140-
Create a new empty object with the `new` statement using declared arbitrary namespace aliases above:
140+
Create a new empty array with the `new` statement.
141141

142142
``` php
143-
$a = new MuArr; // Create new instance of MutableArray by namespace alias
143+
$a = new MutableArray; // Create new instance of MutableArray
144144
// or
145-
$a = new ImArr; // Create new instance of ImmutableArray by namespace alias
145+
$a = new ImmutabelArray; // Create new instance of ImmutableArray
146+
// or
147+
$a = new MuArr; // using namespace aliases
146148
```
147149

148-
or with default values, passed an array to the constructor:
150+
or with default values, passed to the constructor in an array:
149151

150152
``` php
151-
$a = new MuArr([1, 2, 3]);
153+
$a = new MutableArray([1, 2, 3]);
152154
// or
153-
$a = new ImArr([1, 2, 3]);
155+
$a = new ImmutabelArray([1, 2, 3]);
154156
```
155157

156-
Also, a new object could be created with one of few public `static` methods
157-
that starts with `create` prefix and provide additional useful functionality:
158+
Also, new objects can be created with one of the public static methods
159+
prefixed with 'create':
158160

159161
* [create](#create)
160162
* [createFromJson](#createfromjson)
@@ -164,7 +166,7 @@ that starts with `create` prefix and provide additional useful functionality:
164166

165167
## Usage
166168

167-
You can get access to the instance values like with simple PHP `array` behaviour:
169+
You can get access to the values like with the familiar PHP array syntax:
168170

169171
``` php
170172
use Arrayzy\MutableArray as A;
@@ -178,16 +180,18 @@ $a[3] = 'd'; // or use $a->offsetSet(3, 'd') method
178180
$a->toArray(); // [0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd']
179181

180182
print $a[1]; // 'b'
181-
// or use corresponding method
183+
// or use the corresponding method
182184
print $a->offsetGet(1); // 'b'
183185
```
184186

185-
> **NOTE:** Further will be used the `A` namespace alias to shorten usage examples, but keep in mind
186-
that the usage are suitable for both `MutableArray` and `ImmutableArray` in this case.
187+
*NOTE: The following methods and principles apply to `ImmutableArray` and
188+
`MutableArray` alike. In the examples provided they are are interchangeable and
189+
aliased with `A`.*
187190

188191
### Chaining
189192

190-
Use chaining methods for fast usage:
193+
194+
Methods may be chained for ease of use:
191195

192196
``` php
193197
$a = A::create(['a', 'b', 'c']);
@@ -197,16 +201,16 @@ $a
197201
->offsetSet(3, 'd')
198202
->offsetSet(null, 'e')
199203
->shuffle()
200-
->reindex() // or any other method that return the current instance
204+
->reindex() // or any other method that returns the current instance
201205
;
202206

203207
$a->toArray(); // [0 => 'c', 1 => 'a', 2 => 'e', 3 => 'd', 4 => 'b']
204208
```
205209

206210
### Converting
207211

208-
Easily converting instance array elements to a simple PHP `array`, `string`,
209-
`readable string` or `JSON` format:
212+
Easily convert instance array elements to a simple PHP `array`, `string`,
213+
readable `string` or JSON format:
210214

211215
* [toArray](#toarray)
212216
* [toJson](#tojson)
@@ -282,14 +286,16 @@ $a->toArray(); // [0 => 'a', 1 => 'b', 2 => 'c']
282286

283287
### createClone
284288

285-
Keep in mind, that in PHP variables contains only reference to the object, **NOT** the same object:
289+
Creates a shallow copy of the array.
290+
291+
Keep in mind, that in PHP variables contain only references to the object, **NOT** the object itself:
286292

287293
``` php
288294
$a = A::create(['a', 'b', 'c']);
289-
$b = $a; // $a and $b are different variables referenced to the same object ($a === $b)
295+
$b = $a; // $a and $b are different variables referencing the same object ($a === $b)
290296
```
291297

292-
So if you **DO NOT** want to modify current instance, you need to clone it manually first:
298+
So if you **DO NOT** want to modify the current array, you need to clone it manually first:
293299

294300
``` php
295301
$a = A::create(['a', 'b', 'c']);
@@ -300,7 +306,7 @@ $b = $a->createClone(); // $a !== $b
300306

301307
### createFromJson
302308

303-
Creates an instance array from a valid `JSON` string:
309+
Creates an array by parsing a JSON string:
304310

305311
``` php
306312
$a = A::createFromJson('{"a": 1, "b": 2, "c": 3}');
@@ -319,7 +325,7 @@ $b->toArray(); // [0 => 'a', 1 => 'b', 2 => 'c']
319325

320326
### createFromString
321327

322-
Creates an instance array from a simple PHP `string` with specified separator:
328+
Creates an array from a simple PHP `string` with specified separator:
323329

324330
``` php
325331
$a = A::createFromString('a;b;c', ';');
@@ -328,7 +334,7 @@ $a->toArray(); // [0 => 'a', 1 => 'b', 2 => 'c']
328334

329335
### createWithRange
330336

331-
Creates an instance array with specified range:
337+
Creates an array of a specified range:
332338

333339
``` php
334340
$a = A::createWithRange(2, 6, 2);
@@ -337,6 +343,8 @@ $a->toArray(); // [0 => 2, 1 => 4, 2 => 6]
337343

338344
### current
339345

346+
Position of the iterator.
347+
340348
``` php
341349
$a = A::create(['a', 'b', 'c']);
342350
$a->current(); // 'a'
@@ -404,7 +412,7 @@ $a->export(); // array ( 0 => 'a', 1 => 'b', 2 => 'c', )
404412
``` php
405413
$a = A::create(['a', 'z', 'b', 'z']);
406414
$a->filter(function($value) {
407-
return 'z' !== $value; // exclude 'z' value from array
415+
return 'z' !== $value; // exclude 'z' value from array
408416
});
409417
$a->toArray(); // [0 => 'a', 2 => 'b']
410418
```
@@ -483,7 +491,7 @@ $a->getValues(); // [0 => 'a', 1 => 'b', 2 => 'c']
483491

484492
``` php
485493
$a = A::create(['a', 'b', 'c']);
486-
$a->indexOf('b'); // 1
494+
$a->indexOf('b'); // 1
487495
```
488496

489497
### isEmpty
@@ -571,10 +579,10 @@ $a->offsetGet(1); // 'b' (or use $a[1])
571579

572580
``` php
573581
$a = A::create(['a', 'b', 'd']);
574-
// add new value
582+
// add a new value
575583
$a->offsetSet(null, 'd'); // or use $a[] = 'd';
576584
$a->toArray(); // [0 => 'a', 1 => 'b', 2 => 'd', 3=> 'd']
577-
// replace existing value by key
585+
// replace an existing value by key
578586
$a->offsetSet(2, 'c'); // or use $a[2] = 'c';
579587
$a->toArray(); // [0 => 'a', 1 => 'b', 2 => 'c', 3=> 'd']
580588
```
@@ -620,7 +628,7 @@ $a->push('c', 'd');
620628
$a->toArray(); // [0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd']
621629
```
622630

623-
> Method `push()` allow multiple arguments.
631+
> The `push()` method allows multiple arguments.
624632
625633
### reduce
626634

@@ -705,7 +713,7 @@ $a->toArray(); // [0 => 'd', 1 => 'b', 2 => 'c', 3 => 'a']
705713

706714
### toArray
707715

708-
Converts instance array to a simple PHP `array`:
716+
Convert the array to a simple PHP `array`:
709717

710718
``` php
711719
$a = A::create(['a', 'b', 'c']);
@@ -714,7 +722,7 @@ $a->toArray(); // [0 => 'a', 1 => 'b', 2 => 'c']
714722

715723
### toJson
716724

717-
Converts instance array to a `JSON` string:
725+
Creates a JSON string from the array:
718726

719727
``` php
720728
$a = A::create(['a' => 1, 'b' => 2, 'c' => 3]);
@@ -763,17 +771,17 @@ $a->toArray(); // [0 => 'y', 1 => 'z', 2 => 'a', 3 => 'b']
763771
$a = A::create(['a', 'b', 'c']);
764772
$a->walk(function(&$value, $key) {
765773
$key++; // the $key variable passed by value, (original value will not modified)
766-
$value = $value . $key; // the $value variable passed by reference (modify original value)
774+
$value = $value . $key; // the $value variable passed by reference (modifies original value)
767775
});
768776
$a->toArray(); // [0 => 'a1', 1 => 'b2', 2 => 'c3']
769777
```
770778

771779
## Links
772780

773-
Feel free to create an [Issue][3] or [Pull Request][4] if you find a bug
774-
or just want to propose improvement suggestion.
781+
Feel free to create an [Issue][3] or [Pull Request][4] if you find a bug
782+
or just want to propose an improvement suggestion.
775783

776-
Look at the [Stringy][5] if you are looking for a PHP **string** manipulation library in OOP way.
784+
Look at the [Stringy][5] if you are looking for a PHP **string** manipulation library in an OOP way.
777785

778786
[Move UP](#arrayzy)
779787

0 commit comments

Comments
 (0)