OnlineCBT Logo OnlineCBT
PHP · LESSON 5

Operators and Expressions

By Ratan Updated: 16 Oct 2026

Master arithmetic, assignment, comparison, logical, spaceship operator (<=>), and null coalescing (??).

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

1. Arithmetic Operators

Used to perform mathematical computations:

2. Assignment Operators

Used to write and update variable values:

3. Comparison Operators

Used in conditional statements to test equality and relational order:

Operator Name Description Example
== Equal True if values are equal after type coercion. 5 == "5" // true
=== Identical True only if values AND data types are equal. 5 === "5" // false
!= or <> Not equal True if values are not equal. 10 != 20 // true
!== Not identical True if value or type does not match. 5 !== "5" // true
<=> Spaceship Returns -1 (less), 0 (equal), or 1 (greater). 5 <=> 10 // -1

4. Logical Operators

  • && (AND): True if both operands are true.
  • || (OR): True if at least one operand is true.
  • ! (NOT): Inverts boolean truth value.

5. Ternary and Null Coalescing Operator (??)

= 18) ? "Eligible to vote" : "Minor";

// Null Coalescing Operator: returns first operand if set and not null
$username = $_GET['user'] ?? "Guest User";
echo "Welcome, " . $username;

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
Address Contact

+91 7877547686

E-mail

onlinecbtportal@gmail.com

Helpline Number

+91 7877547686


Click To Download
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat