{"name":"BIS_fnc_addToPairs","title":"BIS fnc addToPairs","type":"function","url":"https://community.bistudio.com/wiki/BIS_fnc_addToPairs","revid":352076,"updated":"2024-02-01T23:24:42Z","groups":["Arrays"],"status":"ok","games":{"arma3":"0.76"},"since":"arma3 0.76","arma3_since":"0.76","description":"Adds given value to pair array, stored under unique key.\n\n```\nIf value is found:\n\na) both values are scalars: values are added and stored as a single scalar\n\nb) one or both values are array: values are added and stored as a single array\n\nc) anything else: an array is created and both values are stored there\n```\n\n> [!NOTE]\n> Function by default modifies the input array. This can be overrriden by setting '_copyArray' param to true.","syntaxes":[{"syntax":"[array, key, value, copyArray] call BIS_fnc_addToPairs","params":[{"name":"array","type":"Array","description":"array to search through","type_expr":"Array"},{"name":"key","type":"String","description":"key to search for","type_expr":"String"},{"name":"value","type":"Number","optional":true,"default":"nil","description":"default return value if no match was found","type_expr":"Number","text":"value: Number - (Optional, default nil) default return value if no match was found"},{"name":"copyArray","type":"Boolean","optional":true,"default":"false","description":"true to copy the array and return it, false to modify the original array","type_expr":"Boolean","text":"copyArray: Boolean - (Optional, default false) true to copy the array and return it, false to modify the original array"}],"returns":{"type":"Array","type_expr":"Array","description":"resulting modified array or a copy"}}],"examples":[{"code":["[[[\"apple\",3],[\"pear\",2]],\"pear\",10] call BIS_fnc_addToPairs; // Returns [[\"apple\",3],[\"pear\",12]]"]},{"code":["[[[\"apple\",3],[\"pear\",2]],\"apple\",-2] call BIS_fnc_addToPairs; // Returns [[\"apple\",1],[\"pear\",2]]"]},{"code":["[[[\"greetings\",\"Hello!\"],[\"rudewords\",\"\"]],\"greetings\",\"Hi!\"] call BIS_fnc_addToPairs; // Returns [[\"greetings\",[\"Hello!\",\"Hi!\"]],[\"rudewords\",\"\"]]"]}],"see_also":["find","findIf","BIS_fnc_findInPairs","BIS_fnc_getFromPairs","BIS_fnc_removeFromPairs","BIS_fnc_setToPairs"]}