✅ PHP Objective Questions (MCQs)
Basic Level
- PHP stands for:
- a) Personal Home Page
- b) Pretext Hypertext Processor
- c) Hypertext Preprocessor ✅
- d) None of the above
- Which symbol is used to declare a variable in PHP?
- a) &
- b) $ ✅
- c) #
- d) @
- Which of the following is a PHP loop structure?
- a) foreach ✅
- b) loop
- c) repeat
- d) iterate
- PHP is a __________ language.
- a) Compiled
- b) Interpreted ✅
- c) Machine
- d) Assembly
- Which of the following is used to get data from a form using the GET method?
- a) $_POST
- b) $_GET ✅
- c) $_FORM
- d) $_REQUEST
- Which function is used to include a file in PHP?
- a) include() ✅
- b) import()
- c) load()
- d) require_once()
- Which function starts a session in PHP?
- a) start_session()
- b) begin_session()
- c) session_start() ✅
- d) session_begin()
- Which operator is used for concatenation in PHP?
- a) +
- b) . ✅
- c) &
- d) *
- Which of the following is not a data type in PHP?
- a) Integer
- b) Float
- c) Character ✅
- d) Boolean
- Which of the following is used to get the length of a string?
- a) count()
- b) size()
- c) strlen() ✅
- d) strlength()
Intermediate Level
- What will
echo 10 + "5 days";
output?- a) Error
- b) 105
- c) 15 ✅
- d) 10
- Which keyword is used to define a class in PHP?
- a) define
- b) class ✅
- c) object
- d) struct
- PHP arrays are:
- a) Homogeneous
- b) Indexed only
- c) Associative only
- d) Both indexed and associative ✅
- Which function is used to check if a file exists?
- a) file_exist()
- b) fileexists()
- c) file_exists() ✅
- d) is_file_exist()
- Which version of PHP introduced
namespace
?- a) PHP 4
- b) PHP 5.2
- c) PHP 5.3 ✅
- d) PHP 7
- How do you define a constant in PHP?
- a) constant()
- b) const =
- c) define() ✅
- d) #define
- Which function is used to redirect to another page in PHP?
- a) header() ✅
- b) redirect()
- c) goto()
- d) location()
- What is the default file extension of PHP files?
- a) .html
- b) .php ✅
- c) .xml
- d) .js
- Which of the following is the correct way to comment in PHP?
- a) // comment ✅
- b) — comment
- c)
- d) ## comment
- Which function is used to connect to a MySQL database in PHP (Procedural)?
- a) mysqli_open()
- b) mysql_connect()
- c) mysqli_connect() ✅
- d) db_connect()
Advanced Level
- Which PHP super global is used to access session variables?
- a) $_SESSION ✅
- b) $_POST
- c) $_GET
- d) $_SERVER
- What is the default port for MySQL in PHP?
- a) 1433
- b) 1521
- c) 3306 ✅
- d) 8080
- What does
isset()
function do?- a) Returns true if variable is set ✅
- b) Initializes a variable
- c) Sets a value
- d) Deletes a variable
- What does
empty()
function do?- a) Checks if variable has empty value ✅
- b) Deletes variable
- c) Sets variable
- d) Returns variable
- Which function is used to sort an array in descending order?
- a) sort()
- b) rsort() ✅
- c) dsort()
- d) asort()
- Which function is used to send emails in PHP?
- a) send_mail()
- b) smtp_mail()
- c) mail() ✅
- d) mail_send()
- Which of the following is the scope of a variable defined with
global
keyword?- a) Local
- b) Script-wide
- c) Global ✅
- d) Static
- Which function is used to prevent SQL injection in PHP (with MySQLi)?
- a) clean_string()
- b) sanitize()
- c) mysqli_real_escape_string() ✅
- d) escape_sql()
- Which PHP function gets the current script filename?
- a) $_SERVER[“PHP_FILE”]
- b) $_SERVER[“SCRIPT_FILENAME”] ✅
- c) $_SERVER[“FILE_NAME”]
- d) get_filename()
- Which of these is true for
require
andinclude
?- a) Both stop script on failure
- b) Only include stops on failure
- c)
require
stops,include
does not ✅ - d) None
Bonus MCQs
- PHP is case-sensitive?
- a) Yes ✅
- b) No
- c) Only for functions
- d) Only for variables
- What will
echo (false == 0);
return?- a) 0
- b) 1 ✅
- c) Error
- d) false
- How to write a multiline comment in PHP?
- a)
<!-- -->
- b)
# #
- c)
/* */
✅ - d)
// //
- a)
- PHP code is executed on:
- a) Client side
- b) Server side ✅
- c) Both
- d) None
- What does
explode()
do in PHP?- a) Compress strings
- b) Joins array
- c) Splits strings into array ✅
- d) Deletes strings
- What does
implode()
do?- a) Splits array
- b) Joins array into string ✅
- c) Copies array
- d) Deletes array
- PHP files can contain:
- a) HTML
- b) JavaScript
- c) PHP code
- d) All of the above ✅
- What is the use of
die()
in PHP?- a) End script and display message ✅
- b) Restart script
- c) Pause script
- d) Loop script
- Which of the following is not a magic constant?
- a) LINE
- b) FILE
- c) MAGIC ✅
- d) DIR
- Which method is safer for form submission?
- a) GET
- b) POST ✅
- c) REQUEST
- d) SESSION
Last 10 Questions
- What is the full form of PDO in PHP?
- a) PHP Data Object ✅
- b) PHP Default Output
- c) Public Data Option
- d) Personal Data Output
- Can PHP be embedded with HTML?
- a) Yes ✅
- b) No
- c) Only in JS
- d) Only in XML
- PHP scripts start with:
- a)
<php>
- b)
<?php ?>
✅ - c)
<script>
- d)
<? ?>
- a)
- The
$_FILES
superglobal is used for:- a) Emailing
- b) File uploading ✅
- c) Session
- d) Cookies
- What is used to destroy a session?
- a) session_end()
- b) destroy_session()
- c) session_destroy() ✅
- d) stop_session()
- What is used to create cookies in PHP?
- a) create_cookie()
- b) setcookie() ✅
- c) cookie_set()
- d) make_cookie()
- Which operator is used for comparison?
- a) =
- b) == ✅
- c) :=
- d) =>
- The default maximum size of a file uploaded in PHP is:
- a) 2MB ✅
- b) 10MB
- c) 5MB
- d) 1MB
$_SERVER['REQUEST_METHOD']
returns:- a) POST or GET ✅
- b) Host IP
- c) Form data
- d) Server name
- PHP was originally developed by:
- a) Rasmus Lerdorf ✅
- b) Dennis Ritchie
- c) James Gosling
- d) Brendan Eich
Leave a Reply