Abbreviations and logical operators in PHP

Simple answer can be given using expression 4 + 5 is equal to 9. Here 4 and 5 are called operands and + is called operator. PHP language supports following type of operators.

-Arithmetic Operators

-Comparision Operators

-Logical (or Relational) Operators

-Assignment Operators

-Conditional (or ternary) Operators

The PHP assignment operators is used to write a value to a variable.

The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right.

x += y x = x + y Addition

x -= y x = x - y Subtraction

x *= y x = x * y Multiplication

x /= y x = x / y Division

x %= y x = x % y Modulus

PHP Logical Operators

and - And - $x and $y - True if both $x and $y are true

or - Or - $x or $y - True if either $x or $y is true

xor -Xor - $x xor $y - True if either $x or $y is true, but not both

&& -And - $x && $y - True if both $x and $y are true

|| - Or - $x || $y - True if either $x or $y is true

! - Not -!$x - True if $x is not true

++$x Pre-increment - Increments $x by one, then returns $x

$x++ Post-increment - Returns $x, then increments $x by one

--$x Pre-decrement Decrements - $x by one, then returns $x

$x-- Post-decrement - Returns $x, then decrements $x by one

Branching statements in PHP

In PHP we have the following conditional statements:

if statement - executes some code only if a specified condition is true.

if...else statement - executes some code if a condition is true and another code if the condition is false.

if...elseif....else statement - selects one of several blocks of code to be executed.

switch statement - selects one of many blocks of code to be executed.

The if statement is used to execute some code only if a specified condition is true. Syntax

if (condition)

{code to be executed if condition is true;}

Use the if....else statement to execute some code if a condition is true and another code if the condition is false. Syntax

if (condition)

{code to be executed if condition is true;}

else{code to be executed if condition is false}

Use the if....elseif...else statement to select one of several blocks of code to be executed.Syntax

if (condition)

{code to be executed if condition is true}

elseif (condition)

{code to be executed if condition is true;}

else

{code to be executed if condition is false}

Use the switch statement to select one of many blocks of code to be executed.Syntax

switch (n)

{case label1:

code to be executed if n=label1; break; case label2:

code to be executed if n=label2;break;case label3:

code to be executed if n=label3;break;

...

default:

code to be executed if n is different from all labels;

}


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: