Search⌘ K
AI Features

Introduction

Explore the concept of functions in PHP, including built-in and user-defined types. Learn how to write, implement, and call functions with or without parameters to perform specific tasks efficiently.

What is a Function? #

A function is a block of code that is written in order to perform a specific task.

Let’s discuss a real-life example to understand the concept better. Suppose that a headmaster wants a teacher to calculate the average marks of the students in a class for a particular subject. The teacher will note down all the marks of the students for that subject, perform the required calculations to calculate the average mark and then report the result to the headmaster.

Functions work in a similar way. They take the required information to ...