Output of PHP programs | Set 4
Predict the output of below PHP programs:
Question 1
<?php "Welcome to w3wiki!" ?> |
Options:
- Error
- Welcome to w3wiki!
- Nothing
- 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 w3wiki." ?> |
Options:
- Error
- I am intern at w3wiki.
- Nothing
- Missing semicolon error
Output:
Error
Explanation: The statement should be print_r(‘I am intern at w3wiki.’) 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 'w3wiki' ; <html> w3wiki </html> ?> |
Options:
- w3wiki
- w3wiki w3wiki
- w3wiki
w3wiki - 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 "w3wiki1" ; echo " w3wiki2" ; ECHO " w3wiki3" ; ?> |
Options:
- w3wiki1 w3wiki2 w3wiki3
- w3wiki1
w3wiki2
w3wiki3 - Error
- w3wiki1 w3wiki3
Output:
w3wiki1 w3wiki2 w3wiki3
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:
- greengreengreen
- greengreen
- green
- Error
Output:
green
Explanation: In PHP, all variables are case-sensitive.
Question 6
<?php # echo "w3wiki" ; echo "# w3wiki" ; ?> |
Options:
- # w3wiki
- w3wiki# w3wiki
- w3wiki
- Error
Output:
# w3wiki
Question 7
<?php echo "echo " w3wiki "" ; ?> |
Options:
- w3wiki
- echo “w3wiki”
- echo w3wiki
- Error
Output:
Error
Explanation: It would have printed echo “w3wiki” if the statement was echo “echo ”w3wiki””;.
Contact Us