PHP Functions

Built-in Function Example

The strlen() function is a built-in PHP function. It counts the number of characters in a string.

The text is: Hello World

The number of characters is: 11

User-Defined Function Example

The addNumbers() function is a function created by the programmer. It takes two numbers, adds them together, and returns the result.

10 + 5 = 15

How Functions Work

Functions are reusable sections of PHP code that perform a particular task. PHP has built-in functions that are already available for programmers to use. Programmers can also create user-defined functions for tasks they need. Functions can receive information through parameters and can return a result. Using functions helps organize code and prevents the same code from being written repeatedly.

Back to Activity 3