User Define Functions:


A function is just a name we give to a block of code that can be executed whenever we need it. The function name can start with a letter or underscore (not a number) 

When you create a function, you first need to give it a name, like myFunction. It's with this function name that you will be able to call upon your function, so make it easy to type and understand.

<?php
function myFunction(){
}
?>
<?php
function writeName() { echo "Pooja Pandya"
echo "My name is " .writeName();
?>
Output:
My name is Pooja Pandya


Argument Function
Default Argument Function
Variable Function
Return Function
<?php
function add($a,$b)
{
$sum=$a+$b;
echo "Sum:-$sum";
} add(10,20);
?>
<?php
function my($type="tea")
{
return "Making a cup of
$type<br>";
}
echo my();
echo my("milk");
?>
<?php
function var1($string)
{
echo $string;
}
$func='var1';
$func('Hello World');
?>
<?php
function square($a)
{
$a*$a;
}
echo square(4);
?>
Output:
Sum:-30
Output:
Making a cup of tea type
Making a cup of milk type
Output:
Hello World
Output:
16


No comments:

Post a Comment

=>Advanced Java Programming (J2EE)

1.  Syllabus 2. Unit Wise Question/Material 3. Paper 4. Previous Paper