Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Is there something similar to the PHP in_array() function in Powershell? [closed]

General Tech Bugs & Fixes
Max. 2000 characters
Replies

usr_profile.png
Liza Sain

User

( 7 months ago )

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...

usr_profile.png
Priyanka Chadda

User

( 7 months ago )

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.

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif