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

Post Top Ad

Post Top Ad

Friday, December 30, 2016

sUPERCODER%2BLOGO

PHP Functions

 
PHP Functions

php


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

No comments:

Post a Comment

Post Top Ad