Certainly! PHP operators are used to perform operations on variables and values. Operators can be categorized into various types. Below are some of the most common types of operators in PHP, along with examples:
These are used for performing arithmetic operations:
$a = 10;
$b = 20;
echo $a + $b; // Output: 30
echo $a - $b; // Output: -10
echo $a * $b; // Output: 200
echo $a / $b; // Output: 0.5
echo $a % $b; // Output: 10
These are used to assign values to variables.
$a = 10;
$b = 20;
$a += $b; // Same as $a = $a + $b; Now $a is 30
$a -= $b; // Same as $a = $a - $b; Now $a is 10 again
These are used to compare two values:
$a = 10;
$b = '10';
var_dump($a == $b); // Output: bool(true)
var_dump($a === $b); // Output: bool(false)
$a = true;
$b = false;
var_dump($a and $b); // Output: bool(false)
var_dump($a || $b); // Output: bool(true)
var_dump(!$a); // Output: bool(false)
$str1 = "Hello, ";
$str2 = "World!";
echo $str1 . $str2; // Output: Hello, World!
These are some of the most commonly used operators in PHP. You can mix and match them to perform complex operations as per your requirements.
UPCET Exam
Click Here
SAAT Exam
Click Here
MHT CET Exam
Click Here
IPU CET Exam
Click Here
KCET Exam
Click Here
COMEDK UG Exam
Click Here
VITEEE Exam
Click Here
BITSAT
Click Here
DSAT: Dayanand Sagar Admission Test
Click Here
Career In Animation in india
Click Here
Merchant Navy Courses in india
Click Here
Interior Design Career in india
Click Here
UGC NET Exam
Click Here
B. Ed Exam
Click Here
AFCAT - Air Force Common Admission Test
Click Here
GATE Exam
Click Here
Joint Entrance Examination (JEE)
Click Here
Common Admission Test (CAT)
Click Here
CDS - Combined Defence Services Exam
Click Here