Find the output of PHP programs | User-defined functions | Set 3: Enhance the knowledge of PHP User-defined functions concepts by solving and finding the output of some PHP programs.
Question 1:
<?php
$ARR = array(
10,
55,
34,
65,
21,
05
);
FUN($ARR);
function fun($A)
{
$VAR = $A . at(0);
foreach ($A as $V)
{
if ($VAR < $V) $VAR = $V;
}
echo $VAR;
}
?>
Question 2:
<?php
$VAR = 5;
FUN($VAR);
function fun(int * $VAL)
{
for ($i = 1;$i <= 10;$i = $i + 1)
{
echo ($i * (*$VAL) . ' ');
}
}
?>
Question 3:
<?php
FUN(add(printf("AB") , printf("CD")));
function fun(int $VAL)
{
for ($i = 1;$i <= 10;$i = $i + 1)
{
echo ($i * $VAL . ' ');
}
}
function add($A, $B)
return ($A + $B);
?>
Question 4:
<?php
FUN(add(printf("AB") , printf("CD")));
function fun(int $VAL)
{
for ($i = 1;$i <= 10;$i = $i + 1)
{
echo ($i * $VAL . ' ');
}
}
function add($A, $B)
{
return ($A + $B);
}
?>
Question 5:
<?php
FUN(log(10));
function fun(int $VAL)
{
for ($i = 1;$i <= 10;$i = $i + 1)
{
echo ($i * $VAL . ' ');
}
}
?>
Answer 1:
Output:
Explanation:
The above program will generate syntax error, because of the below statement.
$VAR = $A.at(0);
Here, we used at(), which is not a built-in function in PHP.
Answer 2:
Output:
Explanation:
The above program will generate syntax error because we created function fun() with parameter $VAL, which looks like a pointer. But PHP does not support pointers.
Answer 3:
Output:
Explanation:
The above program will generate the compile-time error because here we defined a function add() without curly brasses, it is mandatory to use curly brasses in the definition of function in PHP.
Answer 4:
Output:
Explanation:
In the above program we defined two functions fun() and add().
The add() function is used to return the sum of two specified numbers, and fun() function is used to print the table of a specified number.
Now look to the function call.
FUN(add(printf("AB"),printf("CD")));
In the above function call FUN(), the printf("AB") will print "AB" and return 2, similarly printf("AB") will print "AB" and return 2. Then the final function call looks like:
FUN(add(2,2)); FUN(4);
The table of 4 will be printed on the webpage.
Answer 5:
Output:
Explanation:
In the above program, function fun() will print the table of the specified number. The function log(10) will return 2. Then the function call will be FUN(2). Then the table of 2 will be printed on the webpage.
need an explanation for this answer? contact us directly to get an explanation for this answer