Function:-A function is a block a code designed to perform a particular task.
Use:-To increase the readability of program and to perform a task repetitive manner.
Example:-
<?php
function hello_world()
{
echo”Hello world <br>”; //This is a declare a function
echo”Hello world <br>”;
echo”Hello world <br>”;
}
hello_world();
?>
OUTPUT:-
Hello world
Hello world
Hello world
How to use function with return value
Program:-
<?php
function add($num1,$num2)
{
$result add $num1 + $num2;
return result;
}
$add1=add(550+1000);
echo add (550,1000).'<br>’;
$add2=add(560+1000);
echo add (560,1000).'<br>’;
echo $add1*$add2;
?>
OUTPUT:-
1550
1560
2418000
<?php
function add($num1,$num2)
{
$result add $num1 + $num2;
return result;
}
$add1=add(550+1000);
echo add (550,1000).'<br>’;
$add2=add(560+1000);
echo add (560,1000).'<br>’;
echo $add1*$add2;
?>
OUTPUT:-
1550
1560
2418000
0 Comments:
Post a Comment