php-mysql tutorial

Designed By NISHANT GUPTA

  • Home
  • PHP
  • HTML
  • CSS
  • JavaScript
  • JQuery
  • Contact-us
  • Learn HTML

    • Introduction of HTML
    • Image Handling in HTML
    • List Handling in HTML
    • Font Handling in HTML
    • Table Handling in HTML
    • Form Handling in HTML
  • Learn CSS

    • Introduction of CSS
    • Styling Background in CSS
    • Styling Text in CSS
    • Styling Font in CSS
    • Styling Link in CSS
    • Styling List in CSS
    • Styling Table in CSS
    • Styling Div in CSS
    • Styling Span in CSS
    • Positioning in CSS
    • Display in CSS
  • Learn JavaScript

    • Introduction of JavaScript
    • Data Type in JavaScript
    • Variable in JavaScript
    • Oprator in JavaScript
    • Cond. Statement in JavaScript
    • Loop in JavaScript
    • Array in JavaScript
    • Function in JavaScript
    • Date in JavaScript
    • String in JavaScript
    • DOM in JavaScript
    • Event Handling in JavaScript
    • Form Handling in JavaScript
  • Learn PHP-MYSQL

    • Introduction of PHP
    • Decision Control in PHP
    • Loop in PHP
    • Array in PHP
    • Function in PHP
    • Form Handling in PHP
    • File Inclusion in PHP

Function in PHP

Function Introduction

  1. PHP functions are similar to other programming languages. A function is a piece of code which takes one more input in the form of parameter and does some processing and returns a value.
  2. There are two parts which should be clear to us:

      I.  Creating a PHP Function

      II.  Calling a PHP Function

  3. In fact we hardly need to create our own PHP function because there are already more than 1000 of built-in library functions created for different area.
Syntax

function functionName()
{
code to be executed;
}

Example

<html>
<body>

<?php
function greetings()
{
echo “Good Evening. Have a nice time";
}
greetings( );

?>


</body>
</html>

PHP Functions with Parameters

  1. PHP gives us option to pass our parameters inside a function.
  2. We can pass as many parameters as we like.
  3. These parameters work like variables inside our function.
Example

<html>

<head>

<title>Writing PHP Function with Parameters</title>

</head>

<body>

<?php

function addFunction($num1, $num2)

{

  $sum = $num1 + $num2;

  echo "Sum of the two numbers is : $sum";

}

addFunction(10, 20);

?>

</body>

</html>

 

 

Advertisements

 

©  2014 All Rights Reserved  •  Design by >Nishant Gupta.

Privacy Policy • Terms of Use