Skip to content

Commit 04e7c2e

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents c733366 + ff9f368 commit 04e7c2e

36 files changed

+1562
-1363
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929

3030
## Documentation
3131

32-
[https://minwork.gitbook.io/array/](https://minwork.gitbook.io/array/documentation-1/overview)
32+
[https://minwork.gitbook.io/array/](https://minwork.gitbook.io/array/documentation/)
3333

SUMMARY.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,45 @@
11
# Table of contents
22

33
* [Minwork Array](README.md)
4+
* [Documentation](documentation.md)
45

5-
## Documentation
6+
## Common methods
67

7-
* [Overview](documentation-1/overview.md)
8-
* [Common methods](documentation-1/common.md)
9-
* [Validating array](documentation-1/validating-array.md)
10-
* [Manipulating array](documentation-1/manipulating-array.md)
11-
* [Utility methods](documentation-1/utility-methods.md)
8+
* [has](common-methods/has.md)
9+
* [get → getNestedElement](common-methods/get-getnestedelement.md)
10+
* [set → setNestedElement](common-methods/set-setnestedelement.md)
11+
* [remove](common-methods/remove.md)
12+
* [clone](common-methods/clone.md)
13+
* [getKeysArray](common-methods/getkeysarray.md)
14+
15+
## Validating array
16+
17+
* [check](validating-array/check.md)
18+
* [isEmpty](validating-array/isempty.md)
19+
* [isNested](validating-array/isnested.md)
20+
* [isArrayOfArrays](validating-array/isarrayofarrays.md)
21+
* [isAssoc](validating-array/isassoc.md)
22+
* [isUnique](validating-array/isunique.md)
23+
* [isNumeric](validating-array/isnumeric.md)
24+
* [hasKeys](validating-array/haskeys.md)
25+
26+
## Manipulating array
27+
28+
* [Mapping](manipulating-array/untitled.md)
29+
* [Filtering](manipulating-array/filtering.md)
30+
* [Grouping](manipulating-array/grouping.md)
31+
* [Sorting](manipulating-array/sorting.md)
32+
* [Computations](manipulating-array/computation.md)
33+
* [Flattening](manipulating-array/flattening.md)
34+
35+
## Utility methods
36+
37+
* [pack](utility-methods/pack.md)
38+
* [unpack](utility-methods/unpack.md)
39+
* [createMulti](utility-methods/untitled.md)
40+
* [forceArray](utility-methods/forcearray.md)
41+
* [getDepth](utility-methods/getdepth.md)
42+
* [random](utility-methods/random.md)
43+
* [shuffle](utility-methods/shuffle.md)
44+
* [nth](utility-methods/nth.md)
1245

common-methods/clone.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# clone
2+
3+
#### Definition
4+
5+
```php
6+
Arr::clone(array $array): array
7+
```
8+
9+
#### Description
10+
11+
Copy array and clone every object inside it
12+
13+
#### Examples
14+
15+
```php
16+
$object = new class() {
17+
public $counter = 1;
18+
19+
function __clone()
20+
{
21+
$this->counter = 2;
22+
}
23+
};
24+
25+
$array = [
26+
'foo',
27+
'bar',
28+
$object,
29+
'test',
30+
'nested' => [
31+
'object' => $object
32+
]
33+
];
34+
35+
$cloned = Arr::clone($array);
36+
37+
$cloned[0] -> 'foo'
38+
$cloned[2]->counter -> 2
39+
$cloned['nested']['object']->counter -> 2
40+
```
41+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# get → getNestedElement
2+
3+
#### Definition
4+
5+
```php
6+
Arr::getNestedElement(array|ArrayAccess $array, mixed $keys, mixed $default = null): mixed
7+
```
8+
9+
#### Aliases
10+
11+
```php
12+
get($array, $keys, $default = null) -> getNestedElement($array, $keys, $default)
13+
```
14+
15+
#### Description
16+
17+
Get nested array element using specified keys or return `$default` value if it does not exists.
18+
19+
#### Examples
20+
21+
```php
22+
$array = ['key1' => ['key2' => ['key3' => ['test']]]];
23+
24+
Arr::getNestedElement($array, 'key1.key2.key3') -> ['test']
25+
26+
Arr::getNestedElement($array, 'key1.key2.key3.0') -> 'test'
27+
28+
Arr::getNestedElement($array, ['nonexistent', 'key'], 'default') -> 'default'
29+
30+
Arr::getNestedElement($array, 'nonexistent.key.without.default') -> null
31+
```
32+

common-methods/getkeysarray.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# getKeysArray
2+
3+
#### Definition
4+
5+
```php
6+
Arr::getKeysArray(mixed $keys): array
7+
```
8+
9+
#### Description
10+
11+
Transform variable into standardised array of keys.
12+
13+
{% hint style="info" %}
14+
All `$keys` arguments in other methods are normalized using this method
15+
{% endhint %}
16+
17+
#### Examples
18+
19+
```php
20+
Arr::getKeysArray(0) -> [0]
21+
22+
Arr::getKeysArray(null) -> []
23+
24+
Arr::getKeysArray('key') -> ['key']
25+
26+
Arr::getKeysArray('key1.0.key2.1') -> ['key1', '0', 'key2', '1']
27+
28+
Arr::getKeysArray([null, 'key1', '', 'key2', 3.1415, 0]) -> ['key1', 'key2', 0]
29+
```
30+

common-methods/has.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# has
2+
3+
#### Definition
4+
5+
```php
6+
Arr::has(array $array, $keys): bool
7+
```
8+
9+
#### Description
10+
11+
Check if specified \(nested\) key\(s\) exists in array
12+
13+
#### Examples
14+
15+
```php
16+
$array = [
17+
'foo' => [
18+
1,
19+
'test' => [
20+
'abc' => 2,
21+
'def'
22+
],
23+
[
24+
'bar' => true
25+
],
26+
],
27+
];
28+
29+
Arr::has($array, 'foo') -> true
30+
Arr::has($array, 'foo.0') -> true
31+
Arr::has($array, 'foo.test') -> true
32+
Arr::has($array, 'foo.test.abc') -> true
33+
Arr::has($array, ['foo', 1, 'bar']) -> true
34+
35+
Arr::has($array, 'test') -> false
36+
Arr::has($array, []) -> false
37+
Arr::has($array, 'not.existing.key') -> false
38+
```
39+

common-methods/remove.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# remove
2+
3+
#### Definition
4+
5+
```php
6+
Arr::remove(array $array, $keys): array
7+
```
8+
9+
#### Description
10+
11+
Remove element inside array at path specified by keys
12+
13+
#### Examples
14+
15+
```php
16+
$array = [
17+
'foo' => [
18+
1,
19+
'test' => [
20+
'abc' => 2,
21+
'def'
22+
],
23+
[
24+
'bar' => true
25+
],
26+
],
27+
];
28+
29+
Arr::remove($array, 'foo') -> []
30+
Arr::remove($array, '') -> $array
31+
Arr::remove($array, []) -> $array
32+
33+
Arr::remove($array, 'foo.test.abc') ->
34+
[
35+
'foo' => [
36+
1,
37+
'test' => [
38+
// Removed
39+
//'abc' => 2,
40+
'def'
41+
],
42+
[
43+
'bar' => true
44+
],
45+
],
46+
]
47+
48+
Arr::remove($array, 'foo.test') ->
49+
[
50+
'foo' => [
51+
1,
52+
// Removed
53+
/*'test' => [
54+
'abc' => 2,
55+
'def'
56+
],*/
57+
[
58+
'bar' => true
59+
],
60+
],
61+
]
62+
63+
Arr::remove($array, ['foo', 1, 'bar']) ->
64+
[
65+
'foo' => [
66+
1,
67+
'test' => [
68+
'abc' => 2,
69+
'def'
70+
],
71+
[
72+
// Removed
73+
//'bar' => true
74+
],
75+
],
76+
]
77+
```
78+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# set → setNestedElement
2+
3+
#### Definition
4+
5+
```php
6+
Arr::setNestedElement(array $array, mixed $keys, mixed $value): array
7+
```
8+
9+
#### Aliases
10+
11+
```php
12+
set(array $array, $keys, $value) -> setNestedElement(array $array, $keys, $value)
13+
```
14+
15+
#### Description
16+
17+
Set array element specified by keys to the desired value \(create missing keys if necessary\).
18+
19+
#### Examples
20+
21+
```php
22+
$array = ['key1' => ['key2' => ['key3' => ['test']]]];
23+
24+
Arr::setNestedElement([], 'key1.key2.key3', ['test']) -> $array
25+
26+
$array = Arr::setNestedElement($array, 'key1.key2.key4', 'test2');
27+
$array['key1']['key2']['key4'] -> 'test2'
28+
29+
// Create nested array element using automatic index
30+
Arr::setNestedElement($array, 'foo.[].foo', 'bar') ->
31+
[
32+
'foo' => [
33+
[
34+
'foo' => 'bar',
35+
],
36+
],
37+
]
38+
39+
Arr::setNestedElement([], '[].[].[]', 'test') -> [ [ [ 'test' ] ] ]
40+
```
41+

0 commit comments

Comments
 (0)