PHP 8
Lesson 3 of 8
38%
Free Section Starter (Lesson 3)
PHP Free Section Starter Challenge 25 min

3. Functions, Return Types & PHP 8 Match Expressions

Overview: Write typed functions `function calculate(): float` and modern `match()` blocks.

Concept & Syntax Guide

PHP 8 introduced `match()`, a safer and more concise alternative to `switch` that uses strict identity checks `===` and returns an expression directly.

Hands-On Practice Exercise

Create a License Fee Calculator with Match

Write a function `getLicensePrice(string $type): int` using a `match($type)` expression: "single" => 1499, "agency" => 3499, default => 0.

Target Output: Single License: ₹1499
Need a hint? Click here to reveal
Hint: Check syntax carefully and make sure your code contains: Single License: ₹1499
PHP Code Editor
1
2
3
4
5
6
7
8
9
10