PHP Functions | Coding Tag
×

PHP Functions

4371

A PHP function is just a name we give to a block of code that can be used whenever we need it. This might not look like that big of an idea, but believe me, when you know the use of functions, then definitely you will save a lot of time and effort in writing the code in a program.

In PHP, you can see more than 1000 built-in functions. In addition, we can construct our own functions.

In the easiest way, you can create user-defined functions. This function declaration begins with the word "function":

User-defind PHP Function Syntax:

<?php
function functionname() //defining a function
{
code to be executed;
}
functionname(); //calling a function
?>

  • In function name cannot use numeric value, but can use alphabetic letters, underscore and more.
  • PHP functions are similar to other languages.

PHP Function Example:

<?php
function addfunction($x, $y)
{
$sum = $x + $y;
echo "Sum of two numbers is : $sum";
}
addfunction(5, 10);
?>

Result: Sum of two numbers is: 15



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments