PHP Functions

Example 1: Built-In Function

The length of the text is: 11

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

Example 2: User-Defined Function

Hello, Steven!

How Functions Work

Functions are blocks of code that perform a specific task. A function can receive information through parameters and can return a result. PHP has many built-in functions, but programmers can also create their own functions. Functions help organize code and prevent the same code from being repeated.