Functions
1.
How to define a function in PHP?
2.
Type Hinting was introduced in which version of PHP?
3.
Which type of function call is used in line 8 in the following PHP code?
<?php
function calc($price, $tax)
{
$total = $price + $tax;
}
$pricetag = 15;
$taxtag = 3;
calc($pricetag, $taxtag);
?>
4.
What will be the output of the following PHP code?
<?php
function calc($price, $tax="")
{
$total = $price + ($price * $tax);
echo "$total";
}
calc(42);
?>
5.
Which of the following are valid function names?
i) function()
ii) €()
iii) .function()
iv) $function()
6.
Which of the following are valid function names?
i) function()
ii) €()
iii) .function()
iv) $function()
7.
What will be the output of the following PHP code?
<?php
function a()
{
function b()
{
echo 'I am b';
}
echo 'I am a';
}
a();
a();
?>
8.
What will be the output of the following PHP code?
<?php
function a()
{
function b()
{
echo 'I am b';
}
echo 'I am a';
}
b();
a();
?>
9.
What will be the output of the following PHP code?
<?php
$op2 = "blabla";
function foo($op1)
{
echo $op1;
echo $op2;
}
foo("hello");
?>
10.
A function in PHP which starts with __ (double underscore) is known as __________