Blogger templates

Pages

Thursday 18 July 2013

Defining a Function |PHP Tutorial For Beginners


This is complete step by step tutorials that will help you learn basics about defining a PHP functions.

What is function?

A function is a named block of code that performs a specific task, possibly acting upon a set of values given to it, or parameters , and possibly returning a single value. Functions save on compile time no matter how many times you call them, functions are compiled only once for the page. They also improve reliability by allowing you to fix any bugs in one place, rather than everywhere you perform a task, and they improve readability by isolating code that performs specific tasks.

Function Syntax


To define a function, use the following syntax:
function [&] function_name ( [ parameter [, ... ] ] )
{
statement list
}

Example – sum of two numbers

Let’s take a look at a simple function. Example 1 takes two numbers, sum them, and then returns the result
<?php
function sum($number1, $number2)
{
$sumNumbers=$number1 + $number2 ;
return $sumNumbers;
}
?>
The function takes two arguments, $number1 and $number2. Using the + operator, the function sum the numbers in the variable $sumNumbers. Finally, we return the value $sumNumber.
How to call function sum?

echo sum(1, 2);
Output will be 3
or

$num1=1;
$num2=2;
echo sum($num1, $num2);
 

1 comment:

  1. Do you need to increase your credit score?
    Do you intend to upgrade your school grade?
    Do you want to hack your cheating spouse Email, whatsapp, Facebook, instagram or any social network?
    Do you need any information concerning any database.
    Do you need to retrieve deleted files?
    Do you need to clear your criminal records or DMV?
    Do you want to remove any site or link from any blog?
    you should contact this hacker, he is reliable and good at the hack jobs..
    contact : cybergoldenhacker at gmail dot com


    ReplyDelete

give us feed back to improve our service