Computations

sum

Definition

1
Arr::sum(array ...$arrays): array
Copied!

Description

Sum associative arrays by their keys into one array

Examples

1
$arrays = [
2
[
3
'a' => 1,
4
'b' => -3.5,
5
'c' => 0,
6
3
7
],
8
[
9
2,
10
'a' => 0,
11
'c' => -5,
12
'd' => PHP_INT_MAX,
13
],
14
[
15
-5,
16
'b' => 3.5,
17
'a' => -1,
18
'c' => 5,
19
],
20
[
21
'd' => PHP_INT_MAX,
22
],
23
[
24
'd' => 2 * -PHP_INT_MAX,
25
]
26
];
27
28
Arr::sum(...$arrays) ->
29
[
30
0,
31
'a' => 0,
32
'b' => 0,
33
'c' => 0,
34
'd' => 0,
35
]
36
37
Arr::sum([null, '', false], ['1', true, 'test']) -> [1, 1, 0]
Copied!

diffObjects

Declaration

1
Arr::diffObjects(array $array1, array $array2, array ...$arrays): array
Copied!

Description

Compute difference between two or more arrays of objects

Examples

1
$object1 = new \stdClass();
2
$object2 = new \stdClass();
3
$object3 = new \stdClass();
4
5
Arr::diffObjects(
6
[$object3, $object1, $object2],
7
[$object3], [$object2]
8
) -> [1 => $object1]
9
10
Arr::diffObjects(
11
[$object3, $object1, $object2],
12
[$object3],
13
[$object1, $object2]
14
) -> []
15
16
Arr::diffObjects(
17
[$object1],
18
[$object3],
19
[$object2],
20
[]
21
) -> [$object1]
Copied!

intersectObjects

Definition

1
Arr::intersectObjects(array $array1, array $array2, array ...$arrays): array
Copied!

Description

Compute intersection between two or more arrays of objects

Examples

1
$object1 = new \stdClass();
2
$object2 = new \stdClass();
3
$object3 = new \stdClass();
4
5
Arr::intersectObjects(
6
[$object3, $object1, $object2],
7
[$object3, $object2],
8
[$object2]
9
) -> [2 => $object2]
10
11
Arr::intersectObjects(
12
[$object3, $object1, $object2],
13
[$object3],
14
[$object1, $object2]
15
) -> []
16
17
Arr::intersectObjects(
18
[$object1, $object2, $object3, $object1],
19
[$object1, $object2]
20
) -> [$object1, $object2, 3 => $object1]
Copied!
Last modified 2yr ago