16 of 110 menu

PHP Functions Examples

In PHP, a function is defined using the function command. This is followed by a space, the function name, and parentheses.

See an example of such a function:

<?php function func() { return 'text'; } echo func(); // will output 'text' ?>

Parameters can also be passed to a function.

Look at an example of a function that will take a number as a parameter and return its square:

<?php function func($num) { return $num * $num; } echo func(2); // will output 4 echo func(3); // will output 9 ?>

See Also

English
БеларускаяEspañolРусский
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline