PHP Functions - Web Development and Design | Tutorial for Java, PHP, HTML, Javascript PHP Functions - Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Friday, December 30, 2016

PHP Functions

 
PHP Functions

php function


Learn How To Create Functions in PHP.
Function are of Four Types :-

a. No Argument With No Return Type
b.No Argument With Return Type
c.Argument With No Return type
d.Argument With return Type

Now Lets Start.

Example of function :-

function hello() // create function hello
{
//body and scope of function
}


1. No Argument With No Return Type

Code : -

<?php

function hello() // Create a function hello with no argument
{
echo “Calling Function hello”;
}

hello(); // Calling Function hello
// Output : Calling Function Hello
?>

2. No Argument With Return Type

Code : -

<?php

function hello() // Create a function hello with no argument
{
$str=“Calling Function hello”;
return $str; // Return Value
}

echo hello(); // Calling Function hello Here We Use Echo To Print
//Because it Only Return Value Not Print it
// Output : Calling Function Hello
?>

3. Argument With No Return Type

Code : -

<?php


function hello($a) // Create a function hello with argument
{
echo $a; // Print Value
}

$ab=”hello test”;

hello($ab); // Calling Function hello With Parameter $ab
// Output : hello test
?>

4. Argument With Return Type

Code : -

<?php


function hello($a) // Create a function hello with argument
{
$a=ucfirst($a);
return $a; // Return Value
}

$ab=”hello test”;

$out=hello($ab); // Calling Function hello With Parameter $ab
echo $out; // Output : Hello test Here first letter of word is capitalize
?>
Thank You

4 comments:

  1. This is genuinely an awesome read for me. I have bookmarked it and I am anticipating perusing new articles. Keep doing awesome!
    white label website builder

    ReplyDelete
  2. Great Explanation and more useful for anyone.Thanks for sharing...
    PHP Training course in chennai

    ReplyDelete
  3. The comments will make it easier for other developers to make changes to the existing code in future without putting extra time and effort.web design company Toronto

    ReplyDelete

Post Top Ad