Output of PHP programs | Set 4

Predict the output of below PHP programs:

Question 1

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
"Welcome to GeeksforGeeks!"
  
?>

chevron_right


Options:

  1. Error
  2. Welcome to GeeksforGeeks!
  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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Options:

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

Output:

Error

Explanation: The statement should be print_r(‘I am intern at GeeksforGeeks.’) 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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Options:

  1. GeeksforGeeks
  2. GeeksforGeeks GeeksforGeeks
  3. GeeksforGeeks
    GeeksforGeeks
  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

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
Echo "GeeksforGeeks1";
echo " GeeksforGeeks2";
ECHO " GeeksforGeeks3";
  
?>

chevron_right


Options:

  1. GeeksforGeeks1 GeeksforGeeks2 GeeksforGeeks3
  2. GeeksforGeeks1
    GeeksforGeeks2
    GeeksforGeeks3
  3. Error
  4. GeeksforGeeks1 GeeksforGeeks3

Output:

GeeksforGeeks1 GeeksforGeeks2 GeeksforGeeks3

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

Question 5

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Options:

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

Output:

green

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

Question 6

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Options:

  1. # GeeksforGeeks
  2. GeeksforGeeks# GeeksforGeeks
  3. GeeksforGeeks
  4. Error

Output:

# GeeksforGeeks

Question 7

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
echo "echo "GeeksforGeeks"";
  
?>

chevron_right


Options:

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

Output:

Error

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



My Personal Notes arrow_drop_up

Intern at GeeksforGeeks

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.