Functions

PHP requires the keyword: "function" before the function definition.

 

This is followed by the function name and parentheses to accept (zero or more) arguments being sent in to the function.

 

The code block for the function then follows within curly braces { }

 

function myFunction( argument, list ) {

echo "Hello, World!" ;

}

 

A function is called by stating the name of the function and including (zero or more) arguments to be sent to the function within parentheses, followed by a semi-colon ;

 

myFunction( argument, list ) ;

 

<?php

	function myFunction() {

		echo "Hello, World!" ;
	}

	myFunction() ;
?>

Displays:

Hello, World!

 

 

Apart from having the ability to create your own functions, PHP also has a few built-in functions of its own: https://www.php.net/quickref.php

Leave a Reply