{"name":"BIS_fnc_addToPairs","operator":null,"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","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"0.76"}],"since":{"game":"arma3","name":"Arma 3","version":"0.76"},"arma3_since":"0.76","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Adds given value to pair array, stored under unique key.\n\n If value is found:\n\n a) both values are scalars: values are added and stored as a single scalar\n\n b) one or both values are array: values are added and stored as a single array\n\n c) anything else: an array is created and both values are stored there\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","since":null,"effect":null,"exec":null,"params":[{"name":"array","type":"Array","optional":false,"default":null,"description":"array to search through","types":["Array"],"since":null,"text":"array: Array - array to search through"},{"name":"key","type":"String","optional":false,"default":null,"description":"key to search for","types":["String"],"since":null,"text":"key: String - key to search for"},{"name":"value","type":"Number","optional":true,"default":"nil","description":"default return value if no match was found","types":["Number"],"since":null,"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","types":["Boolean"],"since":null,"text":"copyArray: Boolean - (Optional, default false) true to copy the array and return it, false to modify the original array"}],"returns":{"type":"Array","types":["Array"],"description":"resulting modified array or a copy","text":"Array - resulting modified array or a copy"}}],"examples":[{"text":"```sqf\n[[[\"apple\",3],[\"pear\",2]],\"pear\",10] call BIS_fnc_addToPairs; // Returns [[\"apple\",3],[\"pear\",12]]\n```","code":["[[[\"apple\",3],[\"pear\",2]],\"pear\",10] call BIS_fnc_addToPairs; // Returns [[\"apple\",3],[\"pear\",12]]"]},{"text":"```sqf\n[[[\"apple\",3],[\"pear\",2]],\"apple\",-2] call BIS_fnc_addToPairs; // Returns [[\"apple\",1],[\"pear\",2]]\n```","code":["[[[\"apple\",3],[\"pear\",2]],\"apple\",-2] call BIS_fnc_addToPairs; // Returns [[\"apple\",1],[\"pear\",2]]"]},{"text":"```sqf\n[[[\"greetings\",\"Hello!\"],[\"rudewords\",\"\"]],\"greetings\",\"Hi!\"] call BIS_fnc_addToPairs; // Returns [[\"greetings\",[\"Hello!\",\"Hi!\"]],[\"rudewords\",\"\"]]\n```","code":["[[[\"greetings\",\"Hello!\"],[\"rudewords\",\"\"]],\"greetings\",\"Hi!\"] call BIS_fnc_addToPairs; // Returns [[\"greetings\",[\"Hello!\",\"Hi!\"]],[\"rudewords\",\"\"]]"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["find","findIf","BIS_fnc_findInPairs","BIS_fnc_getFromPairs","BIS_fnc_removeFromPairs","BIS_fnc_setToPairs"],"notes":[],"categories":["Arma 3: Functions","Arma 3: New Functions","Function Group: Arrays","Functions","Introduced with Arma 3 version 0.76"],"docblock":null,"filled_from_docblock":[]}