Topics PHP Basics Operators & Expressions
beginner 10 min read

Operators & Expressions

Arithmetic, comparison, logical, and assignment operators in PHP.

Operators

Arithmetic

$sum = 10 + 5;
$diff = 10 - 5;
$product = 10 * 5;
$quotient = 10 / 5;
$mod = 10 % 3;

Comparison

==  // equal (loose)
=== // identical (strict)
!= // not equal
!== // not identical
< > <= >=

Logical

&& // and
|| // or
! // not

Null Coalescing

$name = $_GET["name"] ?? "Guest";
$count = $count ?? 0;

Examples

<?php
$a = 15;
$b = 4;
echo $a + $b; // 19
echo $a % $b; // 3
echo ($a > 10 && $b < 10) ? "yes" : "no";

Your Notes

Sign in to take notes for this lesson.

Discussion

Sign in to join the discussion.

Flashcards

Sign in to create flashcards.