Arrow functions (short closures) in PHP
📖 Scenario: You are working on a small PHP script that processes a list of product prices. You want to apply a discount to each price and then display the discounted prices.
🎯 Goal: Build a PHP script that uses arrow functions (short closures) to apply a discount to each product price and then prints the discounted prices.
📋 What You'll Learn
Create an array called
prices with the exact values: 100, 200, 300Create a variable called
discount and set it to 0.1 (which means 10%)Use an arrow function inside
array_map to calculate discounted pricesPrint the resulting discounted prices array
💡 Why This Matters
🌍 Real World
Applying discounts or taxes to product prices is common in online stores and billing systems.
💼 Career
Understanding arrow functions helps write concise and modern PHP code, which is valuable for web developers.
Progress0 / 4 steps