Skip to content

Chapter 6 of 38

Operators

Apply arithmetic, comparison, logical, assignment, string, and null operators.

34 minutes 10 quick checksBy Subha Prasad
Lesson 6 of 38Course navigation

Lesson content

Read, practise, then check your understanding

Arithmetic uses + - * / % **; strings join with .. Prefer strict === and !==; == coerces. The spaceship operator <=> returns ordering, and logical operators short-circuit.

Practical example

<?php
$display = $input['name'] ?? 'Anonymous';
$allowed = $authenticated && $role === 'editor';
$total += $price * $quantity;
$label = $first . ' ' . $last;

?? handles unset/null array entries, while ?-> stops member access on null. Textual and and or have unexpectedly low precedence. Parenthesize mixed logic and do not use error suppression @ as control flow.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes spaceship operator?
Which PHP term matches this description: The <=> comparison returning -1, 0, or 1.
Which statement best describes null coalescing?
Which PHP term matches this description: The ?? operator selecting a fallback for absent or null values.
Which statement best describes strict equality?
Which PHP term matches this description: The === comparison requiring equal value and type.
Which statement best describes concatenation?
Which PHP term matches this description: String joining with the dot operator.
Which statement best describes short-circuiting?
Which PHP term matches this description: Skipping an && or || operand once the result is known.

0 of 10 checks passed

Your progress is saved on this device.

Operators | PHP Lesson | Subha Prasad