Create a User Defined Function in PHP

A user-defined function declaration starts with the word function:

Syntax
function functionName() {
  code to be executed;
}

<?php
function writeMsg() {
  echo "Hello world!";
}

writeMsg(); // call the function
?>
Scroll to Top