0% found this document useful (0 votes)
80 views11 pages

PHP Unit I MCQ With Answer Bold Without Topic

Uploaded by

priya vajram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views11 pages

PHP Unit I MCQ With Answer Bold Without Topic

Uploaded by

priya vajram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

UNIT -I

1. What does PHP stand for?


a) Personal Home Page b) Private Home Page
c) PHP: Hypertext Preprocessor d) None of the above
2. Which of the following is the correct way to define a variable in PHP?
a) $var_name = "value"; b) var_name = "value";
c) var $var_name = "value"; d) define var_name = "value";
3. Which symbol is used for comments in PHP?
a) / b) /* c) /* */ d) /+
4. Which PHP function is used to include a file in PHP?
a) include() b) require() c) include_once() d) All of the above
5. How do you get the length of a string in PHP?
a) strlen() b) strlength() c) string_length() d) count()
6. Which PHP function is used to send an email?
a) send_email() b) mail() C) email_send() d) mail_send()
7. Which operator is used to concatenate strings in PHP?
A) + b) . c) & d) ,
8. Which function is used to open a file for reading in PHP?
a) open() b) fopen() c) file_open() d) readfile()
9. Which of the following functions can be used to escape special characters in a string for use in an SQL
query?
A) htmlspecialchars() b) mysql_escape_string() c) escape_sql() d) stripslashes()
10. What is the default session timeout in PHP?
A) 15 minutes b) 30 minutes c) 20 minutes d)24 hours
11. Which superglobal array in PHP is used to collect form data after submitting an HTML form?
a) $_GET b) $_POST c) $_REQUEST d) All of the above
12. How do you declare an array in PHP?
a) $array = [1, 2, 3]; b) $array = array(1, 2, 3); c) Both A and B d) $array = (1, 2, 3);
13. What is the correct way to create a function in PHP?
a) function myFunction() {} b) create function myFunction() {}
c) function: myFunction() {} d) def myFunction() {}
14. Which of the following is the correct syntax for a switch statement in PHP?
a) switch (x) { case 1: break; } b) switch: x { case 1: break; }
c) switch (x) { case 1 break; } d) switch(x) -> case 1: break;
15. Which of the following is NOT a valid PHP data type?
a) Integer b) Float c) Double d) Real
16. What does the empty() function in PHP check for?
a) If a variable is null b) If a variable is an empty string
c) If a variable is empty or not set d) All of the above
17. Which PHP function is used to redirect a user to another page?
a) location() b) redirect() c) header() d) location_header()
18. What is the purpose of the $_SERVER superglobal array in PHP?
a) It stores form data b) It stores session data
c) It contains information about the server environment d) It stores cookies
19. Which of the following statements about PHP is true?
a) PHP is a server-side scripting language b) PHP is used for client-side scripting
c) PHP is a database management system d) PHP is only used for web applications
20. Which function is used to terminate the current script in PHP?
a) exit() b) stop() c) terminate() d) end()
21. What does the term "HTTP" stand for?
a) HyperText Transmission Protocol b) HyperText Transfer Protocol
c) Hyper Transfer Text Protocol d) High Transfer Text Protocol
22. Which of the following is used to create the structure of a website?
a) CSS b) HTML c) JavaScript d) PHP
23. Which tag is used to insert an image in an HTML page?
a) <image> b) <img> c) <picture> d) <src>
24. What is the full form of "URL"?
a) Uniform Resource Locator b) Universal Resource Locator
c) Uniform Result Locator d) Universal Result Locator
25. What does CSS stand for?
a) Cascading Style Sheets b) Creative Style Sheets
c) Colorful Style Sheets d) Computer Style Sheets
26. Which HTML element is used for creating a hyperlink?
a) <a> b) <link> c) <button> d) <url>
27. Which protocol is used for secure communication over the internet?
a) HTTP b) FTP c) HTTPS d) SMTP
28. Which of the following is a web browser?
a) Notepad b) Chrome c) WordPad d) Photoshop
29. Which of the following programming languages is commonly used to add interactivity to websites?
a) HTML b) CSS c) JavaScript d) SQL
30. What is the purpose of the <title> tag in HTML?
a) It adds a title to the webpage b) It formats the text
c) It links external files to the page d) It defines the heading of the page
31. What is a dynamic website?
a) A website with fixed content
b) A website that changes based on user interaction or time
c) A website with only text
d) A website with no images
32. Which of the following languages is commonly used to create dynamic websites?
a) HTML b) JavaScript c) CSS d) SQL
33. What does a dynamic website require to display different content to users?
a) A static server b) A content management system (CMS)
c) A web browser d) Only HTML
34. Which of the following is NOT a common method to create dynamic web pages?
a) Server-side scripting b) Client-side scripting c) Flash animation d) Database interaction
35. Which server-side language is often used in dynamic websites?
a) Python b) PHP c) Java d) All of the above
36. In dynamic websites, what role does a database play?
a) It stores the content for display b) It formats the content
c) It manages website security d) It controls navigation
37. Which of the following is used to interact with a database on a dynamic website?
a) CSS b) HTML c) SQL d) JavaScript
38. Which of the following is an example of client-side scripting?
a) PHP b) JavaScript c) ASP d) Python
39. What does AJAX stand for?
a) Asynchronous JavaScript and XML b) Advanced JavaScript and XHTML
c) Adaptive JavaScript and XML d) None of the above
40. What is the advantage of using AJAX in dynamic websites?
a) Faster page loads b) Easier to design websites
c) Improved SEO d) More user interactivity
41. Which HTTP method is commonly used for sending data to a server in dynamic websites?
a) GET b) POST c) PUT d) PATCH
42. What does CMS stand for in the context of dynamic websites?
a) Central Management Software b) Content Management System
c) Creative Marketing System d) Content Manipulation Software
43. Which of these is a popular CMS for creating dynamic websites?
a) WordPress b) HTML5 c) Bootstrap d) JavaScript
44. Which of the following is NOT a benefit of a dynamic website?
a) Real-time content updates b) User-specific content
c) Static page layout d) Interaction with databases
45. What does the term "server-side scripting" refer to?
a) Writing scripts that execute on the client’s browser
b) Writing scripts that execute on the web server
c) Writing scripts that execute on both the client and the server
d) None of the above
46. Which of the following is a commonly used database for dynamic websites?
a) MySQL b) SQLite c) MongoDB d) All of the above
47. In a dynamic website, what is usually stored in a session variable?
a) Web page styles b) User-specific data c) Images d) HTML content
48. Which of these can be used for front-end development in a dynamic website?
a) React b) Google c) Ajax d) All of the above
49. What is the main advantage of using dynamic websites over static websites?
a) Dynamic websites are easier to code
b) Dynamic websites provide personalized and updated content
c) Dynamic websites are faster to load
d) Static websites are more user-friendly
50. Which web development tool helps manage the backend processes of a dynamic website?
a) Bootstrap b) Node.js c) React d) None of the above
51. Which of the following is the correct way to start a PHP block of code?
a) <?php ?> b) <php></php> c) <script></script> d) <?php]?>
52.Which of the following is a valid variable name in PHP?
a) $1variable b) $var$ c) $Variable d) $@var
53. What will the following PHP code output?
function test() {
return "Hello, World!";
}
echo test();
a) Hello, World! b) Hello c) World! d) Error
54.How do you declare an indexed array in PHP?
a) arr = [1, 2, 3]; b) arr = (1, 2, 3); c) $arr = array(1, 2, 3); d) Both a and c
55.What will the following PHP code output?
$x = 10;
if ($x > 5) {
echo "Greater";
} else {
echo "Smaller";
}
a) Greater b) Smaller c) Error d) Nothing
56. Which super global array in PHP is used to collect form data after submitting an HTML form with
method="post"?
a) $_SESSION b) $_POST c) $_GET d) $_COOKIE
57. Which function is used to open a file for reading in PHP?
a) open() b) fopen() c) file_open() d) readfile()
58. Which function is used to set a custom error handler in PHP?
a) error_reporting() b) set_error_handler() c) handle_error() d) trigger_error()
59. How do you instantiate a class in PHP?
a) $obj = new ClassName; b) $obj = ClassName();
c) $obj = new ClassName(); d) $obj = instantiate ClassName;
60. Which PHP function is used to perform a regular expression match?
a) preg_match() b) regex_match() c) match() d) preg_search()
61. Which of the following functions is used to connect to a MySQL database in PHP?
a) mysqli_connect() b) mysql_connect() c) pdo_connect() d) db_connect()
62. How do you embed a PHP variable inside HTML?
a) <?php echo $variable ?> b) <php echo $variable ?>
c) <% echo $variable %> d) <<php echo $variable>>
63. Which function is used to sanitize an email address in PHP?
a) email_filter() b) filter_var() c) sanitize_email() d) validate_email()
64. Which function is used to send a GET request in PHP?
a) file_get_contents() b) get_request() c) http_get() d) send_get_request()
65. What is the major feature introduced in PHP 7?
a) Improved performance b) Object-oriented programming
c) Memory management d) Support for multiple inheritance
66. What does the "Spaceship Operator" (<=>) in PHP 7 do?
a) It compares two values and returns -1, 0, or 1 b) It compares the lengths of two strings
c) It concatenates two values d) It compares two objects for equality
67. Which of the following is a new error handling mechanism introduced in PHP 7?
a) Exception handling b) Error handling with Error class
c) Deprecated functions d) Try-catch block for runtime errors
68. PHP 7 introduced a feature that significantly reduces the memory consumption and increases the
performance of applications. What is this feature?
a) Zend Engine 3.0 b) Improved garbage collection c) JIT compiler d) OPcache
69. Which of the following type declarations were introduced in PHP 7?
a) Nullable types b) Scalar type declarations c) Return type declarations d) All of the above
70. What is the return type of a function when it has no return value in PHP 7?
a) null b) void c) empty d) undefined
71. What is the behavior of the null coalescing operator (??) introduced in PHP 7?
a) It checks if a variable is set and is not null. If true, it returns the value, otherwise, it returns the
second operand.
b) It checks if a variable is null and returns the default value.
c) It sets a default value to a variable.
d) It throws an exception if the variable is not defined.
72. What is the output of the following code snippet in PHP 7?
$a = 10;
$b = 5;
echo $a <=> $b;
a) 1 b) 0 c) -1 d) Error
73. Which of the following functions has been removed in PHP 7?
a) mysql_connect() b) mysqli_connect() c) pg_connect() d) curl_init()
74. Which PHP function in PHP 7 can be used to get the current error level?
a) error_level() b) get_error_level() c) error_reporting() d) get_last_error_level()
75. Which new feature in PHP 7 allows more precise control over which types of errors are caught?
a) Throwable interface b) CatchableError c) try-catch blocks d) set_error_handler()
76. PHP 7 has improved performance by using which of the following?
a) JIT Compiler b) Optimized SQL queries c) Faster I/O operations d) Zend Engine 3.0
77. Which of the following is the correct way to declare a scalar type in PHP 7?
a) function add(int $a, int $b): int b) function add($a, $b): int
c) function add(int $a, $b): int d) function add($a, int $b): int
78. What is the result of the following PHP 7 code snippet?
echo (int)"12.34";
a) 12.34 b) 12 c) 34 d) NaN
79. How does PHP 7 handle type declarations for function parameters?
a) Type declarations are ignored
b) Function parameters can have type declarations for both scalar and class types
c) Type declarations are only allowed for scalar types
d) Function parameters can have default values only
80. PHP 7 supports the following integer size:
a) 32-bit only b) 64-bit only c) Both 32-bit and 64-bit d) 128-bit
81. How does PHP 7 handle assert() in terms of error handling?
a) The assert() function has been removed in PHP 7
b) Assertions are enabled by default
c) Assertions are disabled by default
d) Assertions generate a warning by default
82. Which of the following is a new operator introduced in PHP 7?
a) => b) ?? c) -> d) ::
83. Which of the following improvements were made in PHP 7 regarding arrays?
a) Support for object arrays
b) Improved array sorting functions
c) New array functions for efficient memory management
d) Arrays now support multi-dimensional structures by default
84. Which of the following functions is now more optimized in PHP 7?
a) strlen() b) strpos() c) count() d) array_map()
85. What does XAMPP stand for?
a) X Windows, Apache, MySQL, PHP, Perl b) Xtreme Apache MySQL PHP Perl
c) XWindows Apache MySQL Perl d) XAP PHP Perl MySQL
86. Which of the following is a key component of XAMPP?
a) Apache Web Server b) MySQL Database c) PHP Interpreter d) All of the above
87. What is the main purpose of XAMPP?
a) To run a web server b) To host websites on a cloud
c) To serve as a local development environment d) To run games locally
88. Which component in XAMPP is responsible for processing PHP code?
a) MySQL b) Apache c) PHP d) Perl
89. What is the default port number for Apache server in XAMPP?
a) 80 b) 8080 c) 443 d) 3306
90. Which of the following protocols does Apache server use?
a) FTP b) HTTP c) SMTP d) Telnet
91. What is the default username for MySQL in XAMPP?
a) admin b) root c) user d) guest
92. Which file does XAMPP use to configure the Apache server?
a) php.ini b) httpd.conf c) my.ini d) apache.config
93. Where is the default directory for XAMPP's web server located?
a) /htdocs b) /var/www c) /home/www d) /usr/local/bin
94. Which of the following is NOT included in the XAMPP package?
a) MariaDB b) PHP c) Node.js d) Perl
95. What is the default port number for MySQL in XAMPP?
a) 80 b) 3306 c) 443 d) 8080
96. How can you access the XAMPP control panel?
a) By typing "localhost" in the browser b) By running XAMPP application
c) By accessing the XAMPP folder in the system d) All of the above
97. Which software does XAMPP use for database management?
a) PostgreSQL b) SQLite c) MySQL d) Oracle
98. What is the function of phpMyAdmin in XAMPP?
a) To manage MySQL databases through a graphical interface b) To configure Apache settings
c) To run PHP code d) To manage Perl scripts
99. In which directory would you place your PHP files to run on the XAMPP server?
a) /htdocs b) /public_html c) /www d) /server
100. What is the default URL to access a XAMPP server running on localhost?
a) http://localhost/ b) http://127.0.0.18 c) http://localhost:8078/ d) All of the above
101. How can you stop the Apache server in XAMPP?
a) By clicking "Stop" on the XAMPP control panel b) By closing the XAMPP application
c) By restarting the computer d) All of the above
102. Which version of PHP does XAMPP come with by default?
a) PHP 7 b) PHP 5 c) PHP 8 d) It varies by XAMPP version
103. How can you change the port number of the Apache server in XAMPP?
a) By editing the httpd.conf file b) By editing the php.ini file
c) By editing the my.ini file d) By using the XAMPP control panel
104. What does XAMPP provide for testing web applications locally?
a) Web server b) Database server c) PHP interpreter d) All of the above
105. What does WAMP stand for?
a) Windows, Apache, MySQL, PHP b) Windows, Apache, MySQL, Python
c) Web, Apache, MySQL, PHP d) Web, Apache, MySQL, Python
106. Which of the following is a prerequisite to install WAMP?
a) Windows operating system b) Linux operating system c) macOS d) None of the above
107. What is the first step in the WAMP installation process?
a) Installing MySQL b) Downloading the WAMP installer
c) Configuring Apache d) Starting the WAMP server
108. Which web server does WAMP use?
a) Apache b) Nginx c) IIS d) Tomcat
109. Which database management system is used in WAMP?
a) MySQL b) PostgreSQL c) MongoDB d) SQLite
110. What is the default port number used by Apache in WAMP?
a) 8080 b) 80 c) 443 d) 3306
111. Which version of PHP is included in the latest version of WAMP?
a) PHP 5.6 b) PHP 7.4 c) PHP 8.0 d) PHP 7.2
112. After installing WAMP, what icon appears in the system tray?
a) A red circle b) A green icon c) A blue icon d) A yellow icon
113. Where are the websites stored in WAMP?
a) C:\wamp\www b) C:\wamp\sites c) C:\www d) C:\htdocs
114. What does the WAMP icon turning red indicate?
a) Apache and MySQL are working correctly
b) There is an issue with one or both of Apache or MySQL
c) The server is offline
d) The PHP version is outdated
115. What tool is used to manage MySQL databases in WAMP?
a) phpMyAdmin b) Adminer c) MySQL Workbench d) MySQL CLI
116. How can you access phpMyAdmin in WAMP?
a) Through the WAMP menu in the system tray b) By typing localhost/phpmyadmin in a browser
c) Both A and B d) None of the above
117. Which file is used to configure Apache in WAMP?
a) php.ini b) apache.conf c) httpd.conf d) my.ini
118. Which file is used to configure MySQL in WAMP?
a) php.ini b) my.ini c) httpd.conf d) wamp.ini
119. How do you switch between different versions of PHP in WAMP?
a) Through the WAMP system tray icon > PHP > Version
b) By editing the php.ini file manually
c) By reinstalling WAMP with a different version
d) None of the above
120. What must be done to ensure Apache can run properly on port 80?
a) Disable Windows Firewall b) Make sure no other service (like Skype) is using port 80
c) Set the port to 443 d) Ensure that MySQL is running
121. What is the default directory for WAMP's web server files?
a) C:\wamp\www b) C:\wamp\public c) C:\www d) C:\wamp\server
122. Which command can be used to check if Apache is running on WAMP?
a) apache –v b) service apache2 status c) httpd –v d)ps aux | grep apache
123. What should you do if MySQL is not starting in WAMP?
a) Restart the WAMP server b) Check the error logs
c) Make sure the MySQL service is running d) All of the above
124. Which of the following is NOT a part of the WAMP stack?
a) Windows b) Apache c) MongoDB d) PHP

You might also like