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!
Practical related questions.
1. What is anonymous function?
In PHP, an anonymous function is a function that does not have a name. It is also
known as a closure or a lambda function. An anonymous function can be
assigned to a variable or passed as an argument to another function. It can be
used in situations where you need to create a function quickly without defining it
separately.
2. Write the difference between built in function & user defined function.
The main differences between built-in functions and user-defined functions are
that built-in functions are already included in PHP and optimized for
performance, while user-defined functions need to be defined by the user and
can be customized to meet specific needs.
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.