Code Baaj

No 1 Digital Knowledge Website

Most 50 PHP Objective Question Answer |


PHP Objective Questions (MCQs)

Basic Level

  1. PHP stands for:
    • a) Personal Home Page
    • b) Pretext Hypertext Processor
    • c) Hypertext Preprocessor ✅
    • d) None of the above
  2. Which symbol is used to declare a variable in PHP?
    • a) &
    • b) $ ✅
    • c) #
    • d) @
  3. Which of the following is a PHP loop structure?
    • a) foreach ✅
    • b) loop
    • c) repeat
    • d) iterate
  4. PHP is a __________ language.
    • a) Compiled
    • b) Interpreted ✅
    • c) Machine
    • d) Assembly
  5. Which of the following is used to get data from a form using the GET method?
    • a) $_POST
    • b) $_GET ✅
    • c) $_FORM
    • d) $_REQUEST
  6. Which function is used to include a file in PHP?
    • a) include() ✅
    • b) import()
    • c) load()
    • d) require_once()
  7. Which function starts a session in PHP?
    • a) start_session()
    • b) begin_session()
    • c) session_start() ✅
    • d) session_begin()
  8. Which operator is used for concatenation in PHP?
    • a) +
    • b) . ✅
    • c) &
    • d) *
  9. Which of the following is not a data type in PHP?
    • a) Integer
    • b) Float
    • c) Character ✅
    • d) Boolean
  10. Which of the following is used to get the length of a string?
    • a) count()
    • b) size()
    • c) strlen() ✅
    • d) strlength()

Intermediate Level

  1. What will echo 10 + "5 days"; output?
    • a) Error
    • b) 105
    • c) 15 ✅
    • d) 10
  2. Which keyword is used to define a class in PHP?
    • a) define
    • b) class ✅
    • c) object
    • d) struct
  3. PHP arrays are:
    • a) Homogeneous
    • b) Indexed only
    • c) Associative only
    • d) Both indexed and associative ✅
  4. Which function is used to check if a file exists?
    • a) file_exist()
    • b) fileexists()
    • c) file_exists() ✅
    • d) is_file_exist()
  5. Which version of PHP introduced namespace?
    • a) PHP 4
    • b) PHP 5.2
    • c) PHP 5.3 ✅
    • d) PHP 7
  6. How do you define a constant in PHP?
    • a) constant()
    • b) const =
    • c) define() ✅
    • d) #define
  7. Which function is used to redirect to another page in PHP?
    • a) header() ✅
    • b) redirect()
    • c) goto()
    • d) location()
  8. What is the default file extension of PHP files?
    • a) .html
    • b) .php ✅
    • c) .xml
    • d) .js
  9. Which of the following is the correct way to comment in PHP?
    • a) // comment ✅
    • b) — comment
    • c)
    • d) ## comment
  10. 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

  1. Which PHP super global is used to access session variables?
    • a) $_SESSION ✅
    • b) $_POST
    • c) $_GET
    • d) $_SERVER
  2. What is the default port for MySQL in PHP?
    • a) 1433
    • b) 1521
    • c) 3306 ✅
    • d) 8080
  3. What does isset() function do?
    • a) Returns true if variable is set ✅
    • b) Initializes a variable
    • c) Sets a value
    • d) Deletes a variable
  4. What does empty() function do?
    • a) Checks if variable has empty value ✅
    • b) Deletes variable
    • c) Sets variable
    • d) Returns variable
  5. Which function is used to sort an array in descending order?
    • a) sort()
    • b) rsort() ✅
    • c) dsort()
    • d) asort()
  6. Which function is used to send emails in PHP?
    • a) send_mail()
    • b) smtp_mail()
    • c) mail() ✅
    • d) mail_send()
  7. Which of the following is the scope of a variable defined with global keyword?
    • a) Local
    • b) Script-wide
    • c) Global ✅
    • d) Static
  8. 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()
  9. Which PHP function gets the current script filename?
    • a) $_SERVER[“PHP_FILE”]
    • b) $_SERVER[“SCRIPT_FILENAME”] ✅
    • c) $_SERVER[“FILE_NAME”]
    • d) get_filename()
  10. Which of these is true for require and include?
    • a) Both stop script on failure
    • b) Only include stops on failure
    • c) require stops, include does not ✅
    • d) None

Bonus MCQs

  1. PHP is case-sensitive?
    • a) Yes ✅
    • b) No
    • c) Only for functions
    • d) Only for variables
  2. What will echo (false == 0); return?
    • a) 0
    • b) 1 ✅
    • c) Error
    • d) false
  3. How to write a multiline comment in PHP?
    • a) <!-- -->
    • b) # #
    • c) /* */
    • d) // //
  4. PHP code is executed on:
    • a) Client side
    • b) Server side ✅
    • c) Both
    • d) None
  5. What does explode() do in PHP?
    • a) Compress strings
    • b) Joins array
    • c) Splits strings into array ✅
    • d) Deletes strings
  6. What does implode() do?
    • a) Splits array
    • b) Joins array into string ✅
    • c) Copies array
    • d) Deletes array
  7. PHP files can contain:
    • a) HTML
    • b) JavaScript
    • c) PHP code
    • d) All of the above ✅
  8. What is the use of die() in PHP?
    • a) End script and display message ✅
    • b) Restart script
    • c) Pause script
    • d) Loop script
  9. Which of the following is not a magic constant?
    • a) LINE
    • b) FILE
    • c) MAGIC
    • d) DIR
  10. Which method is safer for form submission?
    • a) GET
    • b) POST ✅
    • c) REQUEST
    • d) SESSION

Last 10 Questions

  1. 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
  2. Can PHP be embedded with HTML?
    • a) Yes ✅
    • b) No
    • c) Only in JS
    • d) Only in XML
  3. PHP scripts start with:
    • a) <php>
    • b) <?php ?>
    • c) <script>
    • d) <? ?>
  4. The $_FILES superglobal is used for:
    • a) Emailing
    • b) File uploading ✅
    • c) Session
    • d) Cookies
  5. What is used to destroy a session?
    • a) session_end()
    • b) destroy_session()
    • c) session_destroy() ✅
    • d) stop_session()
  6. What is used to create cookies in PHP?
    • a) create_cookie()
    • b) setcookie() ✅
    • c) cookie_set()
    • d) make_cookie()
  7. Which operator is used for comparison?
    • a) =
    • b) == ✅
    • c) :=
    • d) =>
  8. The default maximum size of a file uploaded in PHP is:
    • a) 2MB ✅
    • b) 10MB
    • c) 5MB
    • d) 1MB
  9. $_SERVER['REQUEST_METHOD'] returns:
    • a) POST or GET ✅
    • b) Host IP
    • c) Form data
    • d) Server name
  10. PHP was originally developed by:
    • a) Rasmus Lerdorf ✅
    • b) Dennis Ritchie
    • c) James Gosling
    • d) Brendan Eich

Leave a Reply

Your email address will not be published. Required fields are marked *