PHP Functions

Example 1: Built-in Function

The text is: Hello World
The number of characters is: 11

Example 2: User-Defined Function

Hello, Akshath! Welcome to Activity 3.

Explanation

Functions are pieces of code which you can reuse that perform specific tasks. PHP includes many built-in functions, such as strlen(), which counts the number of characters in a string. Programmers can also create their own functions for specific tasks. A user-defined function can accept information through parameters, perform an operation, and return a result when the function is called.

Back to Activity 3 Home