Functions in PHP

Functions act as a machine that takes a specified input and returns an output.

In most coding languages, there are pre-defined and user-defined functions.

Pre-defined functions are functions that are native to the language and don't require the developer to define.

Some examples of this in PHP are: stlen (string length), phpinfo, date, etc.

User-defined functions are functions that are created by the developer. User-defined functions can be very powerful, or very basic, depending on the use case.


Pre-Defined Function Examples:

The string, "I enjoy hiking!" is 15 characters long.
The current date is: April 3rd, 2026, 5:09 am

User-Defined Function Example:

This function will test to see if any inputted string matches my name (Gabe)!
David: false
Mary: false
Gabe: true