# Computations

## sum

#### Definition

```php
Arr::sum(array ...$arrays): array
```

#### Description

Sum associative arrays by their keys into one array

#### Examples

```php
$arrays = [
    [
        'a' => 1,
        'b' => -3.5,
        'c' => 0,
        3
    ],
    [
        2,
        'a' => 0,
        'c' => -5,
        'd' => PHP_INT_MAX,
    ],
    [
        -5,
        'b' => 3.5,
        'a' => -1,
        'c' => 5,
    ],
    [
        'd' => PHP_INT_MAX,
    ],
    [
        'd' => 2 * -PHP_INT_MAX,
    ]
];

Arr::sum(...$arrays) ->
[
    0,
    'a' => 0,
    'b' => 0,
    'c' => 0,
    'd' => 0,
]

Arr::sum([null, '', false], ['1', true, 'test']) -> [1, 1, 0]
```

## diffObjects

#### Declaration

```php
Arr::diffObjects(array $array1, array $array2, array ...$arrays): array
```

#### Description

Compute difference between two or more arrays of objects

#### Examples

```php
$object1 = new \stdClass();
$object2 = new \stdClass();
$object3 = new \stdClass();

Arr::diffObjects(
    [$object3, $object1, $object2], 
    [$object3], [$object2]
) -> [1 => $object1]

Arr::diffObjects(
    [$object3, $object1, $object2], 
    [$object3], 
    [$object1, $object2]
) -> []

Arr::diffObjects(
    [$object1], 
    [$object3], 
    [$object2], 
    []
) -> [$object1]
```

## intersectObjects

#### Definition

```php
Arr::intersectObjects(array $array1, array $array2, array ...$arrays): array
```

#### Description

Compute intersection between two or more arrays of objects

#### Examples

```php
$object1 = new \stdClass();
$object2 = new \stdClass();
$object3 = new \stdClass();

Arr::intersectObjects(
    [$object3, $object1, $object2], 
    [$object3, $object2], 
    [$object2]
) -> [2 => $object2]

Arr::intersectObjects(
    [$object3, $object1, $object2], 
    [$object3], 
    [$object1, $object2]
) -> []

Arr::intersectObjects(
    [$object1, $object2, $object3, $object1], 
    [$object1, $object2]
) -> [$object1, $object2, 3 => $object1]
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://minwork.gitbook.io/array/manipulating-array/computation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
