Created
December 3, 2012 19:46
-
-
Save CreativeNotice/4197448 to your computer and use it in GitHub Desktop.
Testing if an Array of Structs contains a key / value pair.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* isKeyValueInArray() | |
* @displayname Is Key In Array | |
* @hint Allows you to loop over array of structures and check if there's atleast one containing a key/value pair. | |
* @param Array arr Array of structures Required | |
* @param String key The key to look for. | |
* @param String value The value of the key to look for. | |
* @returnType Boolean | |
* @since 0.0.1 | |
*/ | |
private function isKeyValueInArray ( required array arr, required string key, required string value ) | |
{ | |
// loop over array of structures and check if there is a matching key / value pair | |
var result = false; | |
for( var i=1; i<=ArrayLen(arguments.arr); i=i+1){ | |
var this_struct = arguments.arr[i]; | |
if( structKeyExists(this_struct, arguments.key) && this_struct[arguments.key] == arguments.value ){ | |
result = true; | |
break; | |
} | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment