Part 8: Functions

Activity 3 Homepage

Example of a Built-in Function: strlen()

The length of the string 'Hello, World!' is 13.

The strlen() function is a built-in PHP function that returns the length of a string.

User-defined Function Example

Example of a User-defined Function: greet()

Hello, Alice!

The greet() function is a user-defined function that takes a name as an argument and returns a greeting message.

How Functions Work

Functions in PHP are blocks of code that can be reused. Built-in functions are provided by PHP, while user-defined functions are created by the programmer. Functions help to organize code, make it more readable, and reduce repetition by encapsulating reusable logic.