BIS fnc getFromPairs: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (template:command argument fix)
m (Text replacement - "(\|[pr][0-9]+ *= *[^- ]*) *- *V([a-z ])" to "$1 - v$2")
 
(35 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{RV|type=function


{{Function|= Comments
|game1= arma3
____________________________________________________________________________________________
|version1= 1.02


| arma3 |= Game name
|gr1= Arrays


|1.02|= Game version
|descr= Searches the associative array for the 1st occurance of the key string and returns the value associated with it. Search is not case sensitiv.
____________________________________________________________________________________________


| <pre>/*
|s1= [array, key, defaultValue] call [[BIS_fnc_getFromPairs]]


Description:
|p1= array: [[Array]] - array to search through
Searches the associative array for the 1st occurance of the key string and returns the value associated with it.


Syntax:
|p2= key: [[String]] - key to search for
_value = [_associativeArray:array,_key:string,_defaultValue] call BIS_fnc_getFromPairs;


Example:
|p3= defaultValue: [[Anything]] - (Optional, default [[nil]]) default return value if no match was found
2 = [[["apple",3],["pear",2]],"pear"] call BIS_fnc_getFromPairs;


Returns:
|r1= [[Anything]] - value associated with the key.
* if found: value stored under the key
* if not found: nil or _defaultValue
*/


</pre><small>''(Placeholder description extracted from the function header by [[BIS_fnc_exportFunctionsToWiki]])''</small> |DESCRIPTION=
|x1= <sqf>[[["apple",3],["pear","test"]],"pear"] call BIS_fnc_getFromPairs; // Returns "test"</sqf>
____________________________________________________________________________________________


| <!-- [] call [[BIS_fnc_getFromPairs]]; --> |SYNTAX=
|x2= <sqf>[[["apple",3],["pear",6]],"pear"] call BIS_fnc_getFromPairs; // Returns "6"</sqf>


|p1= |PARAMETER1=
|seealso= [[find]] [[findIf]] [[BIS_fnc_findInPairs]] [[BIS_fnc_addToPairs]] [[BIS_fnc_removeFromPairs]] [[BIS_fnc_setToPairs]]
 
}}
| |RETURNVALUE=
____________________________________________________________________________________________
 
|x1= <code></code> |=
____________________________________________________________________________________________
 
| |SEEALSO=


{{Note
|user= Benargee
|timestamp= 20141002011700
|text= [[BIS_fnc_findInPairs]] renamed to [[BIS_fnc_getFromPairs]] and now supports all variable types {{Link|http://dev.arma3.com/post/spotrep-00011|Source}}
}}
}}
<h3 style="display:none">Notes</h3>
<dl class="command_description">
<!-- Note Section BEGIN -->
<!-- Note Section END -->
</dl>
<h3 style="display:none">Bottom Section</h3>
[[Category:Function Group: Arrays|{{uc:getFromPairs}}]]
[[Category:Functions|{{uc:getFromPairs}}]]
[[Category:{{Name|arma3}}: Functions|{{uc:getFromPairs}}]]
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on October 2, 2014 - 01:17 (UTC)</dd>
<dt class="note">[[User:Benargee|Benargee]]</dt>
<dd class="note">
[[BIS_fnc_findInPairs]] renamed to [[BIS_fnc_getFromPairs]] and now supports all variable types [http://dev.arma3.com/post/spotrep-00011 Source]
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Latest revision as of 15:53, 8 November 2023

Hover & click on the images for description

Description

Description:
Searches the associative array for the 1st occurance of the key string and returns the value associated with it. Search is not case sensitiv.
Execution:
call
Groups:
Arrays

Syntax

Syntax:
[array, key, defaultValue] call BIS_fnc_getFromPairs
Parameters:
array: Array - array to search through
key: String - key to search for
defaultValue: Anything - (Optional, default nil) default return value if no match was found
Return Value:
Anything - value associated with the key.

Examples

Example 1:
[[["apple",3],["pear","test"]],"pear"] call BIS_fnc_getFromPairs; // Returns "test"
Example 2:
[[["apple",3],["pear",6]],"pear"] call BIS_fnc_getFromPairs; // Returns "6"

Additional Information

See also:
find findIf BIS_fnc_findInPairs BIS_fnc_addToPairs BIS_fnc_removeFromPairs BIS_fnc_setToPairs

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Benargee - c
Posted on Oct 02, 2014 - 01:17 (UTC)
BIS_fnc_findInPairs renamed to BIS_fnc_getFromPairs and now supports all variable types Source