How to create a function in PHP

Creating PHP functions:

   * All functions start with the word "function()"
   * Name the function - It should be possible to understand what the function does by its name. The name can start with a letter or underscore (not a number)
   * Add a "{"  - The function code starts after the opening curly brace
   * Insert the function code
   * Add a "}"  - The function is finished by a closing curly brace

Example

A simple function that writes my name when it is called:

<html>
<body>

<?php
         function writeMyName()
         {
               echo "Kai Jim Refsnes";
         }

        writeMyName();
?>

</body>
</html>

No comments:

Post a Comment