Content health: prewriting stage
This chapter is not yet finished. To speed up the progress, help us fix it at GitHub.


Function is language element that wraps a block of code between curly brackets characters and provide a reusable functionality accross your program.

Let's take a look at a simple example:


function sayHello($name)
    echo 'Hello, '.$name;


Functions can take zero or more arguments. Argument above is $name, which you can pass when calling a function.

// A simple function, without arguments
function functionName() {}

// A function with arguments
function functionName($param1, $param2) {}

Real world programs might contain many functions however for the best reusability you will later on learn classes and objects which are more modern approach to build complex programs.

Found a typo? Something wrong with this content?

Just fork and edit it.

Content of this work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license. Code snippets in examples are published under the CC0 1.0 Universal (CC0 1.0). Thanks to all contributors.