Q:

PHP find output programs (Operators) | set 2

0

Find the output of PHP programs | Operators | Set 2: Enhance the knowledge of PHP Operators concepts by solving and finding the output of some PHP programs.

Question 1:

<?php
    $NUM1 = 16;
    define(NUM2, 2);
    
    $RESULT = power($NUM1, 2) * NUM2;
    echo $RESULT . ' ';
?>

Question 2:

<?php
    $NUM1 = 16;
    $NUM2 = "16";
    
    $RESULT = ($NUM1 == $NUM2);
    echo $RESULT . '@';
    
    $RESULT = ($NUM1 === 16);
    echo $RESULT . '#';
    
    $RESULT = ($NUM1 === $NUM2);
    echo $RESULT . '%';
?>

Question 3:

<?php
    $NUM1 = 16;
    $NUM2 = "16";
    
    $RESULT = ($NUM1 <> $NUM2) ? "HELLO" : "HII";
    echo $RESULT;
?>

Question 4:

<?php
    $NUM1 = 16;
    $NUM2 = "16";
    
    $RESULT = $NUM1 * (16 == $NUM2 && 11 > 2) * 5;
    
    echo $RESULT;
?>

Question 5:

<?php
    $NUM1 = 12;
    $NUM2 = "13";
    
    $RESULT = $NUM1 * ((16 == $NUM2) ? (11 > 2) ? 6 : 5 : 4);
    echo $RESULT;
?>

All Answers

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

Answer 1:

Output:

PHP Warning:  Use of undefined constant NUM2 - assumed 'NUM2' 
(this will throw an Error in a future version of PHP) in
 /home/main.php on line 3
PHP Fatal error:  Uncaught Error: Call to undefined function power() in 
/home/main.php:5
Stack trace:
#0 {main}
  thrown in /home/main.php on line 5

Explanation:

The above program will generate a compilation error because power() is not a built-in function. To calculate the power of a specified number, we need to use pow() function in PHP.

Answer 2:

Output:

1@1#%

Explanation:

In the above program, we defined two variables $NUM1 and $NUM2 initialized with 16 and "16". Here, we used two operators for comparison.

  • '==' (equal operator), which is used to match two values.
  • '===' (identical operator), which is used for the exact match of two values.

The equal operator will math 16 and "16", but the identical operator will not match. The result of an equal and identical operator will be 1 if operand matched successfully.

$RESULT = ($NUM1==$NUM2);
echo $RESULT.'@';

The above statements will print 1@.

$RESULT = ($NUM1==16);
echo $RESULT.'@';

The above statements will print 1#.

$RESULT = ($NUM1===$NUM2);
echo $RESULT.'%';

And the condition ($NUM1===$NUM2) will not return anything. Then it will print '%' only.

Then the final output "1@1#%" will be printed on the webpage.

Answer 3:

Output:

HII

Explanation:

In the above program, we created two variables $NUM1 and $NUM2 initialized with 16 and "16".

$RESULT= ($NUM1<>$NUM2)?"HELLO":"HII";

In the above expression, we used conditional operator, here we used NOT operator "<>", then condition gets false, then "HII" will be assigned to $RESULT.

Then "HII" will be printed on the webpage.

Answer4:

Output:

80

Explanation:

The above program will print 80 on the webpage. In the above program, we created two variables $NUM1 and $NUM2 initialized with 16 and "16" respectively.

Let's evaluate the expression:

Then the final value of $RESULT will be printed on the webpage.

Answer5:

Output:

48

Explanation:

The above program will print 48 on the webpage. In the above program, we created two variables $NUM1 and $NUM2 initialized with 12 and "13" respectively.

Let's evaluate the expression:

$RESULT= $NUM1 * ((16==$NUM2)?(11>2)?6:5:4);  
$RESULT= 12 * ((16=="13")?(11>2)?6:5:4);  
$RESULT= 12 * 4;
$RESULT= 48;

Then final value of $RESULT 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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now