Array map function
📖 Scenario: You work in a bakery that wants to update the prices of some pastries. You have a list of prices, and you want to increase each price by 10% to cover new costs.
🎯 Goal: Use the array_map function in PHP to create a new list of updated prices with a 10% increase.
📋 What You'll Learn
Create an array called
prices with the values 2.50, 3.00, 4.25, 5.00Create a variable called
increase_rate and set it to 0.10Use
array_map with a function that increases each price by increase_ratePrint the new array of updated prices
💡 Why This Matters
🌍 Real World
Updating prices in a list is common in stores and online shops when costs change.
💼 Career
Knowing how to use <code>array_map</code> helps you process lists of data efficiently in PHP, a skill useful for web developers.
Progress0 / 4 steps