0Pricing
PHP Academy · Lesson

Operators

Perform operations using arithmetic, comparison, and logical operators.

Operators is a free PHP Academy lesson on CoddyKit — lesson 3 of 5. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the PHP Academy learning path, one of 5 lessons in the course, and your progress syncs across the web and the CoddyKit app.

1

Operators

Welcome to the next step in PHP! In this lesson, you’ll learn about operators, which are used to perform operations on variables and values. Let’s dive in!

Operators — illustration 1

2

What Are Operators?

Operators are symbols or keywords used to perform operations on variables and values. They help you calculate, compare, and manipulate data in your PHP scripts.

Key Point: PHP provides several categories of operators, including arithmetic, assignment, comparison, logical, and more.

3

Arithmetic Operators

Arithmetic operators are used for basic mathematical operations:

  • +: Addition
  • -: Subtraction
  • *: Multiplication
  • /: Division
  • %: Modulus (remainder)

Example:

<?php
  $a = 10;
  $b = 3;
  echo $a + $b; // Outputs: 13
  echo $a % $b; // Outputs: 1
?>

4

Assignment Operators

Assignment operators assign values to variables. The most common is =, but there are others:

  • +=: Add and assign
  • -=: Subtract and assign
  • *=: Multiply and assign
  • /=: Divide and assign

Example:

<?php
  $x = 5;
  $x += 3; // $x is now 8
  echo $x;
?>

5

Comparison Operators

Comparison operators compare two values and return true or false. Examples:

  • ==: Equal
  • !=: Not equal
  • ===: Identical (equal and same type)
  • <: Less than
  • >: Greater than

Example:

<?php
  $a = 10;
  $b = "10";
  echo $a == $b; // Outputs: 1 (true)
  echo $a === $b; // Outputs: (false)
?>

6

Logical Operators

Logical operators combine multiple conditions. Examples:

  • &&: Logical AND
  • ||: Logical OR
  • !: Logical NOT

Example:

<?php
  $x = true;
  $y = false;
  echo $x && $y; // Outputs: (false)
  echo $x || $y; // Outputs: 1 (true)
?>

7

Increment and Decrement Operators

These operators increase or decrease the value of a variable by 1:

  • ++: Increment
  • --: Decrement

Example:

<?php
  $count = 5;
  echo ++$count; // Outputs: 6
  echo $count--; // Outputs: 6, but $count is now 5
?>

8

String Operators

PHP provides two operators for working with strings:

  • .: Concatenation (joins two strings)
  • .=: Concatenation and assignment

Example:

<?php
  $greeting = "Hello";
  $greeting .= ", World!";
  echo $greeting; // Outputs: Hello, World!
?>

9

<?php
  $a = 10;
  $b = 20;
  echo ($a > $b) ? "A is greater" : "B is greater";
?>

10

Great Job!

Congratulations! You’ve learned about PHP operators, including arithmetic, assignment, comparison, logical, and more. These tools are crucial for performing operations in your scripts. In the next lesson, we’ll explore control structures like if-else and loops. Let’s keep coding!

Operators — illustration 10

Frequently asked questions

Is the “Operators” lesson free?

Yes — the full text of “Operators” is free to read here on the web, and the PHP Academy course includes 5 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the PHP Academy course, upgrade to CoddyKit PRO.

What will I learn in “Operators”?

Perform operations using arithmetic, comparison, and logical operators. You practise PHP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start PHP Academy?

No prior experience is required. PHP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 5, so you can start here or from the beginning and move at your own pace.

How long does the “Operators” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this PHP Academy lesson?

Yes. Every PHP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Variables and Constants
  2. Data Types
  3. Operators
  4. Control Structures
  5. Working with Arrays
← Back to PHP Academy