logo
  • Home
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Contact

PHP Multiple Choice Questions | MCQs | Quiz

PHP Interview Questions and Answers
Pratice PHP questions and answers for interviews, campus placements, online tests, aptitude tests, quizzes and competitive exams.

Get Started

•   Basics - 1
•   Basics - 2
•   Basics - 3
•   Functions
•   PHP In-Built Functions
•   Arrays - 1
•   Arrays - 2
•   Arrays - 3
•   Arrays - 4
•   Arrays - 5
•   Object Oriented PHP - 1
•   Object Oriented PHP - 2
•   Advanced Object Oriented
•   Error Handling
•   Exception Handling
•   PHP Filter
•   Regular Expressions - 1
•   Regular Expressions - 2
•   File System & PHP
•   Date & Timestamp
•   Working with Dates
•   HTML Forms
•   User Authentication
•   Uploading Files with PHP
•   PHP Networking
•   Session Handling - 1
•   Session Handling - 2
•   Website Security
•   Preg Basics
•   Databases Working - 1
•   Databases Working - 2
•   Object Basics - 1
•   Object Basics - 2
•   Updating & Deleting Entries
•   Image Uploading Ability
•   Object Advanced Features1
•   Object Advanced Features2
•   Object Advanced Features3
•   Object Tools - 1
•   Object Tools - 2
•   Object & Design - 1
•   Object & Design - 2
•   Syntax - 1
•   Syntax - 2
•   Variables - 1
•   Variables - 2
•   Variables - 3
•   Variables - 4
•   Echo
•   Print
•   Constants
•   Operators - 1
•   Operators - 2
•   Operators - 3
•   Operators - 4
•   Operators - 5
•   If-Else-If - 1
•   If-Else-If - 2
•   If-Else-If - 3
•   Switch
•   While Loops - 1
•   While Loops - 2
•   For Loops - 1
•   For Loops - 2
•   For Loops - 3
•   Functions - 1
•   Functions - 2
•   Functions - 3
•   Functions - 4
•   Functions - 5
•   Functions - 6

Best Reference Books

PHP Books
« Prev Page
Next Page »

PHP Coding Questions and Answers – Syntax – 1

Posted on May 22, 2013 by Manish

This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Syntax – 1”.

1. What will be the output of the following PHP code ?

  1. <?php
  2. "Hello World"
  3. ?>

a) Error
b) Hello World
c) Nothing
d) Missing semicolon error
View Answer

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

2. What will be the output of the following PHP code ?

  1. <?php
  2. print_r "Hello world"
  3. ?>

a) Error
b) Hello World
c) Nothing
d) Missing semicolon error
View Answer

Answer: a
Explanation: The statement should be print_r(‘Hello World’) 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.

3. What will be the output of the following PHP code ?

  1. <?php
  2. echo 'Hello World';
  3. <html>
  4. Hello world
  5. </html>
  6. ?>

a) Hello world
b) Hello World Hello World
c) Hello world
Hello World
d) Syntax Error
View Answer

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

4. What will be the output of the following PHP code ?

  1. <?php
  2. Echo "Hello World1";
  3. echo " Hello world2";
  4. ECHO " Hello world3";
  5. ?>

a) Hello world1 Hello world2 Hello World3
b) Hello world1
Hello world2
Hello World3
c) Error
d) Hello world1 Hello world3
View Answer

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

5. What will be the output of the following PHP code ?

  1. <?php
  2. $color = "red";
  3. echo "$color";
  4. echo "$COLOR";
  5. echo "$Color";
  6. ?>

a) redredred
b) redred
c) red
d) Error
View Answer

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

6. What will be the output of the following PHP code ?

  1. <?php
  2.  # echo "Hello world";
  3.  echo "# Hello world"; 
  4. ?>

a) # Hello world
b) Hello world# Hello world
c) Hello world
d) Error
View Answer

Answer: a
Explanation: # is a single line comment.

7. What will be the output of the following PHP code ?

  1. <?php
  2. echo "<i>Hello World</i>"
  3. ?>

a) Hello world
b) Hello world in italics
c) Nothing
d) Error
View Answer

Answer: b
Explanation: You can use tags like italics, bold etc. inside php script.

8. What will be the output of the following PHP code ?

  1. <?php
  2. echo "echo "Hello World"";
  3. ?>

a) Hello world
b) echo “Hello world”
c) echo Hello world
d) Error
View Answer

Answer: d
Explanation: It would have printed echo “Hello world” if the statement was echo “echo \”Hello World\””;.

9. What will be the output of the following PHP code ?

  1. <?php
  2. <?php
  3. echo "Hello world";
  4. ?>
  5. ?>

a)
b) Hello world
c) Nothing
d) Error
View Answer

Answer: d
Explanation: You can not have php tags inside a php tag.

10. What will be the output of the following PHP code ?

  1. <?php
  2. $color = red;
  3. echo "\$color";
  4. ?>

a) red
b) $color
c) \red
d) Error
View Answer

Answer:b
Explanation: To print red remove the \.

Sanfoundry Global Education & Learning Series – PHP Programming.

To practice all questions on PHP Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.

« Prev Page - PHP Questions & Answers – Object and Design-2
» Next Page - PHP Coding Questions and Answers – Syntax – 2
« PHP Questions & Answers – Object and Design-2
PHP Coding Questions and Answers – Syntax – 2 »

Deep Dive @ Sanfoundry:

  1. Compilers Questions and Answers
  2. PHP Questions and Answers
  3. PHP Coding Questions and Answers – Operators – 1
  4. PHP Coding Questions and Answers – Variables – 1
  5. PHP Coding Questions and Answers – Functions – 1
  6. PHP Coding Questions and Answers – Functions – 5
  7. PHP Coding Questions and Answers – Variables – 2
  8. PHP Coding Questions and Answers – Functions – 6
  9. PHP Coding Questions and Answers – Echo
  10. PHP Coding Questions and Answers – Variables – 3
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below:
LinkedIn | Facebook | Twitter | Google+

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
TOS & Privacy
Jobs
Bangalore Training
Online Training
SAN Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry