Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP if statement - either but not both

Tags:

php

What's the correct way to rephrase this statement so that it passes if either variable is set, but not if BOTH are set?

if (isset($_GET['txnid']) || isset($_GET['complete'])){
like image 781
daninthemix Avatar asked Feb 08 '16 13:02

daninthemix


People also ask

Can you use&& in PHP?

PHP provides an alternate syntax for the || operator — the or operator. It also provides an alternate syntax for && operator — the and operator. These operators have the advantage of making our code more human readable.

How compare two variables in if condition in PHP?

The comparison operator called Equal Operator is the double equal sign “==”. This operator accepts two inputs to compare and returns true value if both of the values are same (It compares only value of variable, not data types) and return a false value if both of the values are not same.

What is a PHP conditional?

PHP Conditional Statements if statement - executes some code if one condition is true. if...else statement - executes some code if a condition is true and another code if that condition is false. if... elseif...else statement - executes different codes for more than two conditions.


Video Answer


1 Answers

Yes, its called an XOR, it will be true if either one of them is true, but not both.

if (isset($_GET['txnid']) XOR isset($_GET['complete'])){

Source: PHP: Logical Operators

like image 157
Khoon Avatar answered Oct 27 '22 00:10

Khoon