Output of PHP programs | Set 4

Predict the output of below PHP programs:

Question 1




<?php
  
"Welcome to zambiatek!"
  
?>


Options:

  1. Error
  2. Welcome to zambiatek!
  3. Nothing
  4. Missing semicolon error

Output:

Nothing

Explanation: If you need to output something onto the screen you’ll need to use echo or print_r.

Question 2




<?php
  
print_r "I am intern at zambiatek."
  
?>


Options:

  1. Error
  2. I am intern at zambiatek.
  3. Nothing
  4. Missing semicolon error

Output:

Error

Explanation: The statement should be print_r(‘I am intern at zambiatek.’) to print Hello world. Also if there is only one line then there is no requirement of a semicolon, but it is better to use it.

Question 3




<?php
  
echo 'zambiatek';
  
<html>
zambiatek
</html>
  
?>


Options:

  1. zambiatek
  2. zambiatek zambiatek
  3. zambiatek
    zambiatek
  4. Syntax Error

Output:

Syntax Error

Explanation: Parse error: syntax error, unexpected ‘<‘ on line 2. You can not use the html tag inside php tags.

Question 4




<?php
  
Echo "zambiatek1";
echo " zambiatek2";
ECHO " zambiatek3";
  
?>


Options:

  1. zambiatek1 zambiatek2 zambiatek3
  2. zambiatek1
    zambiatek2
    zambiatek3
  3. Error
  4. zambiatek1 zambiatek3

Output:

zambiatek1 zambiatek2 zambiatek3

Explanation: In PHP, all user-defined functions, classes, and keywords (e.g. if, else, while, echo, etc.) are case-insensitive.

Question 5




<?php
  
$color = "green";
echo "$color";
echo "$COLOR";
echo "$Color";
  
?>


Options:

  1. greengreengreen
  2. greengreen
  3. green
  4. Error

Output:

green

Explanation: In PHP, all variables are case-sensitive.

Question 6




<?php # echo "zambiatek";
   
echo "# zambiatek"
  
?>


Options:

  1. # zambiatek
  2. zambiatek# zambiatek
  3. zambiatek
  4. Error

Output:

# zambiatek

Question 7




<?php
  
echo "echo "zambiatek"";
  
?>


Options:

  1. zambiatek
  2. echo “zambiatek”
  3. echo zambiatek
  4. Error

Output:

Error

Explanation: It would have printed echo “zambiatek” if the statement was echo “echo ”zambiatek””;.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button