Functions

Example 1 — Built-in function strlen

Text: This sentence has this many characters: Length: 40

Example 2 — User-defined function rectangleArea

Area: 32

Explanation

A function is a reusable set of instructions. If a function takes arguments, call the function with those arguments to hydrate the parameters in the function. Calling a function runs the instructions with the supplied parameters.

PHP has many built in functions available to developers. One of those is strlen()... which returns the length of a string. htmlspecialcharacters() is a commonly used function to ensure the data is readable and help prevent XSS attacks

Users can define and create functions as needed as well. rectangleArea() is a user defined funtion

Return to Activity 3 index