User Defined Function
Home Courses Community Support
User Defined Function

PHP function is very similar to other language functions. Function is a code block which take input parameter, process taken inputs and return a value. PHP have around 1000 built-in functions like function_exists(), func_get_arg() etc. Along with built-in functions PHP facilitate you to create your own functions.

To work on functions you just need to know how to call a built-in/created function and how to create a functions.

enlightenedA function require to call to execute it. No function execute on page load.

Creating a Function

Such functions called user define function. To create a function you need to start it with a keyword function.

Below is the syntax to create a function.

function Function_Name() {

// Code to execute when the function will be called.



Below is the example of creating a function. We will create a function for greetings.

// Creating a function
function welcome() {
echo "Welcome to the world of Geeksdemy. You have learned how to create/call a function.";

// Calling a function


Welcome to the world of Geeksdemy. You have learned how to create/call a function.


enlightenedWe need to take care of following while writing the name of a function-

  • Give the function a name that reflects what the function does
  • The function name can start with a letter or underscore (not a number)


Follow PHP official website to check all predefine functions.



← Preview

ForEach Loop

Next →

Function with Argument


Our mission is to provide highly effective and quality education via innovative solutions. Geeksdemy look forward to bridge the gap between in-demand technology and academics in order to deliver innovative, easy, interesting and affordable learning across the Globe.


  • Python
  • Game Development with Unity 3D
  • Arduino
  • PCB & Circuit Designing
  • Robotics and Embedded C
  • 8051/8052 Embedded Systems
  • QuadCopter & UAV
  • MATLAB with Robotics
  • Raspberry Pi
Learn On the Go!
Get the Android App
Get the iOS App