简体   繁体   中英

How to use isset to check multiple values within a array in php?

I will try my best to explain this, I have the following array which has multiple values. I am trying to use isset to check if two values are within the array. I have followed the php documentation here: http://php.net/manual/en/function.isset.php

$nfl = array(#stands for national footbal league
    'patriots' => 'New England Patriots',
    'jets' => 'New York Jets', etc..........)



       if(isset($nfl[$team11][$team12]) )
        {
   # my code is here
    }

If I use only one team it works

if(isset($nfl[$team]))

Can anyone help me please?

You have to check them one at a time but you can do that in one function call as isset() accepts multiple variables to check.

If multiple parameters are supplied then isset() will return TRUE only if all of the parameters are set. Evaluation goes from left to right and stops as soon as an unset variable is encountered.

if(isset($nfl[$team11], $nfl[$team12])) { // all must be true
    // do stuff
}

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