Q:

PHP find output programs (User-defined functions) | set 3

belongs to collection: PHP Find Output Programs

0

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 . ' ');
        }
    }
?>

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer 1:

Output:

PHP Fatal error:  Uncaught Error: Call to undefined function at() 
in /home/main.php:15
Stack trace:
#0 /home/main.php(11): fun(Array)
#1 {main}
  thrown in /home/main.php on line 15

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:

PHP Parse error:  syntax error, unexpected '*', 
expecting variable (T_VARIABLE) in /home/main.php on line 5

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:

PHP Parse error:  syntax error, unexpected 'return' (T_RETURN), 
expecting '{' in /home/main.php on line 13

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:

ABCD4 8 12 16 20 24 28 32 36 40

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:

2 4 6 8 10 12 14 16 18 20

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

total answers (1)

PHP Find Output Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
PHP find output programs (String Functions) | set ... >>
<< PHP find output programs (User-defined functions) ...