Complete Guide to PHP Operators with Examples for Beginners

Complete Guide to PHP Operators with Examples for Beginners

PHP lo programming chestunnappudu values tho calculations cheyadam, variables ki values assign cheyadam, conditions ni compare cheyadam mariyu different conditions ni combine cheyadam lanti operations chala common ga untayi. Ee operations ni easy ga perform cheyadaniki PHP lo operators ni use chestam.

Operator ante oka special symbol or keyword. Idi values or variables madhya oka particular operation ni perform cheyadaniki use avutundi. For example, + addition kosam, – subtraction kosam, == comparison kosam, and && multiple conditions ni check cheyadaniki use chestam.

PHP lo different types of operators unnayi. Prati operator ki different purpose untundi. Arithmetic operators calculations kosam, assignment operators values ni variables lo assign cheyadaniki, comparison operators values ni compare cheyadaniki, logical operators multiple conditions ni check cheyadaniki use avutayi.

Ee article lo PHP operators ni beginners ki easy ga artham ayye vidhamga simple explanations mariyu practical examples tho telusukundam. Arithmetic, Assignment, Comparison, Logical, Increment/Decrement mariyu String operators ni step by step ga chuddam.

Example 1: Arithmetic Operators

<?php

$a = 20;
$b = 10;

echo “Addition: ” . ($a + $b) . “<br>”;
echo “Subtraction: ” . ($a – $b) . “<br>”;
echo “Multiplication: ” . ($a * $b) . “<br>”;
echo “Division: ” . ($a / $b) . “<br>”;
echo “Modulus: ” . ($a % $b);

?>

Output:

Addition: 30
Subtraction: 10
Multiplication: 200
Division: 2
Modulus: 0

Explanation:

Ikkada $a mariyu $b ane two variables lo values store chesam. +, -, *, /, % operators ni use chesi different mathematical operations perform chesam.
Example 2: Comparison and Logical Operators
<?php

$age = 25;
$salary = 30000;

if (($age >= 18) && ($salary >= 20000))
{
echo “The person is eligible”;
}
else
{
echo “The person is not eligible”;
}

?>

Output:

The person is eligible

Explanation:

Ee example lo >= comparison operator tho age mariyu salary conditions ni check chestunnam. && logical AND operator kabatti rendu conditions true ayinappude if block execute avutundi.

Operator in php:

Complete Guide to PHP Operators are special symbol for the purpose to make actions performed by the user .

There are seven operators in php.those are

1.Arthematic operator

2.Assignment operator

3.logical operators

4.comparision operators

5.string operators

6.increment/decrement operators

Arthematic operators:

arthematic operators used for mathematical calculation using operands.

+       Addition

–       Subtraction

*      Multiplication

/      Division

%     Modulus

Program using arthematic operators in php:

<?php

$a=60;

$b=30;

echo “addition : “.($a+$b).”\n”; //addition

echo “sub : ” . ($a-$b).”\n”; //Subtraction

echo “mul : “. ($a*$b) .”\n”; //multiplication

echo “div : ” . ($a/$b). “\n”; //division

echo “mod : “. ($a%$b).”\n”; //modulus

?>

Output1:

addition: 90

sub : 30

mul :1800

div : 2

mod : 0

Program 2 with different inputs:

<?php

$a=80;

$b=20;

echo “addition : “.($a+$b).”\n”; //addition

echo “sub : ” . ($a-$b).”\n”; //Subtraction

echo “mul : “. ($a*$b) .”\n”; //multiplication

echo “div : ” . ($a/$b). “\n”; //division

echo “mod : “. ($a%$b).”\n”; //modulus

?>

Output 2:

addition : 100

sub : 60

mul :1600

div : 4

mod :0

Assignment operators in php:

These assignment operators are used to perform some operations and that value is stored in that assignment variable.this is similar to arthematic operators but the difference is we can the value in specific assigned variable.

Symbols Explanation

= Assignment

+= Addition and assignment

-= Subtraction and assignment

*= Multiplication andassignment

/= Division and assignment

%= Modulus and assignment

program for assignment operators using php:

<?php

$a=50;

echo $a.”\n”;

//Addition and assignment

$b=40;

$b +=20;

echo $b;

//Subtraction and assignment

$b=40;

$b -=20;

echo $b.”\n”;

//Multiplication and assignment

$b=40;

$b *=20;

echo $b.”\n”;

//Division and assignment

$b=40;

$b /=20;

echo $b.”\n”;

//Modulus and assignment

$b=40;

$b %=20;

echo $b.”\n”;

?>

Output:

50

60

20

800

2

0

Program 2 with different outputs:

?php

$a=100;

echo $a.”\n”;

//Addition and assignment

$b=92;

$b +=20;

echo $b;

//Subtraction and assignment

$b=60;

$b -=12;

echo $b.”\n”;

//Multiplication and assignment

$b=13;

$b *=13;

echo $b.”\n”;

//Division and assignment

$b=60;

$b /=30;

echo $b.”\n”;

//Modulus and assignment

$b=20;

$b %=10;

echo $b.”\n”;

?>

Output 2:

I00

112

48

169

2

0

Logical operators in php:

Logical operators are used to check the condition and return the value.logical operators are used major programs.it is very important concepts in operators without these logical operators we cannot find the way to check both conditions at the time.

Symbols. Explanation

&& Logical AND // if both conditions are true that the answer is true

|| Logical OR// if one condition is true then the answer is true

! Logical not // if condition is true the answer is false.

Program for logical operators in php:

<?php

$a=40;

$b=50;

//Logical and

if(($a>20) && ($b>40))

echo “statements are true”.”\n”;

//Logical OR

if(($a>20)||($b>40))

echo “statements are true”.”\n”;

//Logical not

if (!$a=30)

echo “false”;

?>

output:

statements are true

Statement are true

false

Comparison operators in php:

Comparison operators are used to check the condition wheather it is satisfy or not.

There many operators.in comparison.those are greater than,less than,equal too,greater than are equal,less than or equal,not equal.

Symbols. Explanation

Equal to//$a==10

< Less than //$a<10

> Greater than // $a>20

<= Less than are equal to //$a<=20

>= Greater than are equal to

//$a>=40

Increment/decrement operators in php:

Increment/decreament operators are used for increment value by 1 or decreament value by 1.

Once the value is assigned after some time we need to increase the variable value.then we are using this increment and decrement operators.

Symbol. Explanation

++ Increment

— decrement

Program for increment/decrement operators in php:

<? php

$a=2;

echo $a++;

echo $a–;

echo ++$a;

echo –$a;

?>

String operators in php

String are are used in php for concatenation.

. Symbol Indicare for concatenation.

Conclusion

PHP operators anedi programming lo different types of operations perform cheyadaniki chala important. Arithmetic operators tho mathematical calculations cheyochu, assignment operators tho values ni variables ki assign cheyochu, comparison operators tho two values ni compare cheyochu.

Alage logical operators multiple conditions ni combine cheyadaniki, increment and decrement operators values ni one by one increase or decrease cheyadaniki, string operators strings ni combine cheyadaniki use avutayi.

Ee operators basic ga artham cheskunte PHP programs lo calculations, conditions, variables and string operations ni easy ga handle cheyagalugutam. Beginners munduga prati operator syntax and simple examples ni practice chesi, tarvata vatini conditional statements and real-world programs lo use cheyadam practice cheyali.

3 thoughts on “Complete Guide to PHP Operators with Examples for Beginners”

Leave a Comment