Checking If Then statements in PHP

When I write an if statement, I check the variable as follows:

if(isset($_GET['username']){
 echo "set";
 } else {
 echo "unset";
}

How can I get an if statement to check if two variables are set:

if(isset($_GET['username'] & $_GET['firstname'])){
 echo "set";
 } else {
 echo "unset";
}

So basically, how can I check two things in an if statement right away?

+5
source share
7 answers

Check out the PHP manual on control structures and logical operators :

if(isset($_GET['username']) && isset($_GET['firstname'])) {
    echo "set";
} else {
    echo "unset";
}

Using solo &performs a bitwise operation , which is definitely not what you want.

andis also synonymous with syntax &&, as other answers have shown.

EDIT. , , isset, isset. , - - , .

+11
if ( isset($_GET['username'], $_GET['firstname']) ) {
    echo 'Set!';
}

isset , , isset() TRUE , , , .

+7
if ( isset($_GET['username']) && isset($_GET['firstname']) )
+2

&& ( ), ( )

isset true , if true, if false.

+1

,

echo ((isset ($ _ GET ['username']) && isset ($ _ GET ['firstname']))? "set": "unset" );

+1
if (isset($_GET['username']) AND isset($_GET['firstname']))
{
    echo "set";
}
else
{
    echo "unset";
}
0
if (isset($_GET['username']) && isset($_GET['firstname']))
{ 
    echo "set"; 
} 
else 
{ 
    echo "unset"; 
}

: PHP

0

All Articles