Skip to content

Instantly share code, notes, and snippets.

@CreativeNotice
Created December 3, 2012 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save CreativeNotice/4197448 to your computer and use it in GitHub Desktop.
Save CreativeNotice/4197448 to your computer and use it in GitHub Desktop.
Testing if an Array of Structs contains a key / value pair.
/**
* 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