PHP 7.4 Functions - Exercise
You must be using PHP 7.4, as some of features mentioned below may not be available in PHP earlier versions.
Create multiple short programs using PHP that shall perform the functionality described below. You shall be able to do most of stuff if you have attended PHP Functions lecture but some functionality may require you to read more on web to complete, to help you in self learning.
Create multiple short programs using PHP that shall perform the functionality described below. You shall be able to do most of stuff if you have attended PHP Functions lecture but some functionality may require you to read more on web to complete, to help you in self learning.
Program #1.
Write a PHP function that shall take an integer parameter representing year. Your function shall return a boolean representing whether the year is a leap year or not. Mention the type on prototype but do not use strict_type mode. If user passes, a non integer data, you functions hall return null.
Program #2.
There is a special type of function in PHP, call variadic functions or variable length arguments. Make a function that user shall call passing none, single or any number of numeric paramters. The function shall return sum of all numbers. If nothing is passed as argument, the function shall return 0.
Program #3.
Make a function, whenever its called, it shall print how many times the function has been called so far since the PHP script execution started. Print count at end of function. The function shall also update the count, such that when the function is called next time, it prints an updated value. (Hint: use static variable in function.)
Program #4.
We can write 'void' in return type in PHP functions. Make a function where the declared return type is void. And read about this, when its used and how. Write any function to demonstrate its usage, keeping the strict_types ON.
Program #3.
Make a function, whenever its called, it shall print how many times the function has been called so far since the PHP script execution started. Print count at end of function. The function shall also update the count, such that when the function is called next time, it prints an updated value. (Hint: use static variable in function.)
Program #4.
We can write 'void' in return type in PHP functions. Make a function where the declared return type is void. And read about this, when its used and how. Write any function to demonstrate its usage, keeping the strict_types ON.
Comments
Post a Comment