PHP Practical 6
PHP Practical 6
AIM: Write a simple PHP program to demonstrate the use of simple function and
parameterized function.
THEORY:
Default Functions: These functions do not require any input values to operate.
They perform a set of actions based on their internal logic. For example, a
function that displays the current date and time would be considered a default
function as it doesn't need any external data to function.
Parameterized Functions: These functions accept input values, known as
parameters or arguments, which influence their behaviour. These parameters
allow the function to be more flexible and adaptable to different situations. For
instance, a function that calculates the area of a rectangle would require
parameters for the length and width of the rectangle to perform the calculation
accurately.
PROGRAM 1:
AIM: PHP Program to use simple function
CODE:
<?php
function add(){
$a = 10;
$b = 20;
echo "Value of a: $a <br>";
echo "Value of b: $b <br>";
echo "Addition of two numbers: ", $a+$b;
}
add();
?>
OUTPUT:
PROGRAM 2:
AIM: PHP Program to use parameterized function
CODE:
<?php
function area($len, $bre){
echo "Length of the Rectangle : ", $len, "<br>";
echo "Breadth of the Rectangle : ", $bre, "<br>";
echo "Area of the Rectangle : ", $len*$bre;
}
area(4,5);
?>
OUTPUT: