Reputation: 1775
I have an array that looks like this:
$team = array("tom"=>"35",
"beck"=>"18",
"Gerald"=>"15");
I also am parsing data from a loop which gives me the following strings $name and $num
I would like to build a php if statement that will do the following:
As an example, lets assume the following:
I have this so far:
if (in_array($num, $team)) {
// do something
}
What's missing is for it to check the second condition mentioned above.
Following the above example, it should fail, since the $num value is "25", whereas it is "35" in the array.
Upvotes: 1
Views: 32
Reputation: 31749
You can try to check the $name
key with value of $num
-
$team = array("tom"=>"35",
"beck"=>"18",
"Gerald"=>"15");
if(isset($team[$name]) && $team[$name] == $num) {
// Your code
}
in_array
will check for the value
's existence in the array without considering the key
.
Upvotes: 2