PHP Functions

Built-in function: strlen()

strlen('Activity 3') returns 10 characters for this example.

User-defined function: greetStudent()

greetStudent('Adam') returns Hello, Adam!

Explanation

A function groups instructions under a name so they can be called when needed. PHP provides built-in functions such as strlen(), which measures this string. I also defined greetStudent() myself: it accepts a name as an argument, builds a greeting, and returns the result. Calling it with another name would produce a different greeting without rewriting the instructions.

Back to Activity 3