Functions in PHP

  • Post author:
  • Post category:PHP
  • Post comments:0 Comments

Functions in PHP

Functions in PHP are used to organize code into reusable blocks that can be called from anywhere in the program. Functions are declared with the keyword function followed by the function name, and can optionally accept parameters.

For example, a simple function that takes two parameters and returns the sum of the two parameters:

function add($x, $y) {
    return $x + $y;
}

In this example, the function add() is declared and takes two parameters, $x and $y. The function will then return the sum of the two parameters. The output of this function when called with the parameters 5 and 10 would be 15.

Leave a Reply