Function declaration and calling
📖 Scenario: You are creating a simple PHP program to greet users by their name. This is like writing a small helper that says hello whenever you ask it.
🎯 Goal: Build a PHP program that declares a function called greet which takes a name and returns a greeting message. Then call this function with a specific name and print the greeting.
📋 What You'll Learn
Declare a function named
greet that accepts one parameter called name.The function should return a string greeting in the format: "Hello, {name}!".
Call the
greet function with the argument "Alice".Print the result of the function call.
💡 Why This Matters
🌍 Real World
Functions help organize code into reusable blocks, like helpers that do one job well. This is common in all programming tasks.
💼 Career
Knowing how to declare and call functions is essential for any PHP developer to write clean, maintainable code.
Progress0 / 4 steps