php exp6 23
php exp6 23
Experiment No: 6
Title of Experiment Write a simple PHP program to demonstrate use of simple function and
parameterized function.
Program code:
<html>
<head>
<title>Writing PHP Function</title>
</head>
<body>
<?php
/* Defining a PHP Function */
function writeMessage(){
echo "Welcome to PHP world!";
}
/* Calling a PHP Function */
writeMessage();
?>
</body>
</html>
Output:
Welcome to PHP world!
2. Write the difference between built in function & user defined function.
In summary, built-in functions are part of the PHP core, while user-
defined functions are defined by the user. Both types of functions can
be useful in different situations.
Exercise
1. Write a code to perform addition of 3 numbers using function.
2. Write a PHP program to check whether number is even or odd using function.
3. Write a PHP program to print factorial of number using function.