---
name: "BIS_fnc_addToPairs"
type: function
status: ok
groups: ["Arrays"]
arma3_since: "0.76"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/BIS_fnc_addToPairs
revid: 352076
updated: 2024-02-01T23:24:42Z
---

# BIS_fnc_addToPairs

*Function · Arrays · Arma 3 v0.76*

## Description

Adds given value to pair array, stored under unique key.

 If value is found:

 a) both values are scalars: values are added and stored as a single scalar

 b) one or both values are array: values are added and stored as a single array

 c) anything else: an array is created and both values are stored there

> [!NOTE]
> Function by default modifies the input array. This can be overrriden by setting '_copyArray' param to true.

## Syntax

```sqf
[array, key, value, copyArray] call BIS_fnc_addToPairs
```

**Parameters:**

- `array`: [Array](../topics/Array.md) - array to search through
- `key`: [String](../topics/String.md) - key to search for
- `value`: [Number](../topics/Number.md) - (Optional, default [nil](../commands/nil.md)) default return value if no match was found
- `copyArray`: [Boolean](../topics/Boolean.md) - (Optional, default [false](../commands/false.md)) [true](../commands/true.md) to copy the array and return it, [false](../commands/false.md) to modify the original array

**Returns:** [Array](../topics/Array.md) - resulting modified array or a copy

## Examples

### Example 1

```sqf
[[["apple",3],["pear",2]],"pear",10] call BIS_fnc_addToPairs; // Returns [["apple",3],["pear",12]]
```

### Example 2

```sqf
[[["apple",3],["pear",2]],"apple",-2] call BIS_fnc_addToPairs; // Returns [["apple",1],["pear",2]]
```

### Example 3

```sqf
[[["greetings","Hello!"],["rudewords",""]],"greetings","Hi!"] call BIS_fnc_addToPairs; // Returns [["greetings",["Hello!","Hi!"]],["rudewords",""]]
```

## See also

[find](../commands/find.md) · [findIf](../commands/findIf.md) · [BIS_fnc_findInPairs](../functions/BIS_fnc_findInPairs.md) · [BIS_fnc_getFromPairs](../functions/BIS_fnc_getFromPairs.md) · [BIS_fnc_removeFromPairs](../functions/BIS_fnc_removeFromPairs.md) · [BIS_fnc_setToPairs](../functions/BIS_fnc_setToPairs.md)

<sub>Source: [BI Community Wiki — BIS fnc addToPairs](https://community.bistudio.com/wiki/BIS_fnc_addToPairs) (revision 352076).</sub>
