简体   繁体   中英

PowerShell: Multiple Conditions within IF Statement

Im struggling to understand why the following IF statement doesn't work...

I have a PS array:

$lunchArray = @('Pizza', 'Sushi', 'Sandwich')

However the following Foreach/IF statement doesn't work as expected.

foreach ($lunch in $lunchArray) {
    if ($lunch -eq 'Pizza' -and $lunch -eq 'Sushi') {
        "YAY" # not working...
    }
}

What am I doing wrong here?

TIA

$lunchArray = @('Pizza', 'Sushi', 'Sandwich')

foreach ($lunch in $lunchArray) {
    if ('Pizza' -eq $lunch -or 'Sushi' -eq $lunch) {
        "YAY" # not working...
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM