0

Is there a way of finding out if a given value is in an array without iterating through it? Something like the in_array function in PHP...

2

Yes, there is. Example:

$arrColors = "blue", "red", "green", "yellow", "white", "pink", "orange", "turquoise"
$arrColors -contains "black"
#$arrColors -notcontains "black" #obvious
#$color = $arrColors -like "bl*" #return all values that begin with "bl"

or

$array = 1,2,5,8,3,4,5
$array.Contains(2)

Both examples return a boolean.

Not the answer you're looking for? Browse other questions tagged or ask your own question.