Almost all solved MCQs for you..

PHP MCQs for Beginners

PHP MCQs for Beginners

1: Which of the following is NOT a valid PHP data type?

  • a) String
  • b) Integer
  • c) Array
  • d) Boolean

c) Array

2: What does PHP stand for?

  • a) Personal Hypertext Processor
  • b) Preprocessed Hypertext Pages
  • c) PHP: Hypertext Preprocessor
  • d) PHP Hypertext Page

c) PHP: Hypertext Preprocessor

3: Which of the following is the correct way to start a PHP script?

  • a) <?php start ?>
  • b) <?php
  • c) <?start?>
  • d) <?php>

b)

4: Which PHP function is used to open a file for reading?

  • a) read_file()
  • b) open_file()
  • c) fopen()
  • d) file_open()

c) fopen()

5: What is the correct operator for concatenating two strings in PHP?

  • a) .
  • b) +
  • c) –
  • d) *

a) .

6: What is the output of the following PHP code: echo strlen(“Hello World”); ?

  • a) 10
  • b) 11
  • c) 12
  • d) 13

b) 11

7: Which of the following is used to comment a single line in PHP?

  • a) //
  • b) /*
  • c) #
  • d) ;

a) //

8: Which of the following PHP functions is used to delete a file?

  • a) delete_file()
  • b) remove_file()
  • c) unlink()
  • d) file_delete()

c) unlink()

9: Which superglobal variable in PHP is used to retrieve information about HTTP cookies?

  • a) $_SESSION
  • b) $_COOKIE
  • c) $_GET
  • d) $_POST

b) $_COOKIE

10: What is the output of the following PHP code: echo 10 % 3; ?

  • a) 1
  • b) 3
  • c) 7
  • d) 0

a) 1

PHP MCQ Online Test

11: Which of the following is NOT a comparison operator in PHP?

  • a) ===
  • b) ==
  • c) <>
  • d) <=>

d) <=>

12: Which PHP function is used to redirect the user to a different URL?

  • a) redirect()
  • b) header()
  • c) location()
  • d) forward()

b) header()

13: What is the correct way to end a PHP statement?

  • a) ;
  • b) :
  • c) .
  • d) {

a) ;

14: Which PHP function is used to check if a file or directory exists?

  • a) is_file()
  • b) file_exists()
  • c) exists()
  • d) check_file()

b) file_exists()

15: What is the output of the following PHP code: echo strtoupper(“php is fun”); ?

  • a) php is fun
  • b) PHP is FUN
  • c) PHP IS FUN
  • d) php IS fun

c) PHP IS FUN

16: Which of the following is used to start a session in PHP?

  • a) session_start()
  • b) start_session()
  • c) session()
  • d) initiate_session()

a) session_start()

17: Which PHP function is used to retrieve the current date and time?

  • a) date()
  • b) time()
  • c) now()
  • d) current_datetime()

a) date()

18: What is the output of the following PHP code: echo 2 + “3”; ?

  • a) 5
  • b) 23
  • c) 32
  • d) Error

a) 5

19: Which of the following is used to define a constant in PHP?

  • a) define()
  • b) const()
  • c) constant()
  • d) set_constant()

a) define()

20: What does the PHP function “mysqli_connect()” do?

  • a) Connects to a MySQL database
  • b) Connects to a Microsoft SQL Server database
  • c) Connects to a MongoDB database
  • d) Connects to a PostgreSQL database

Answer: a)

PHP Exam Questions and Answers

21: What is the correct way to declare a PHP array?

  • a) array(1, 2, 3)
  • b) [1, 2, 3]
  • c) (1, 2, 3)
  • d) {1, 2, 3}

b) [1, 2, 3]

22: Which of the following functions is used to remove whitespace from the beginning and end of a string in PHP?

  • a) trim()
  • b) strip()
  • c) remove_whitespace()
  • d) clean()

a) trim()

23: What is the output of the following PHP code: echo strlen(“PHP”); ?

  • a) 1
  • b) 2
  • c) 3
  • d) 4

c) 3

24: Which PHP function is used to convert a string to lowercase?

  • a) strtolower()
  • b) lcstring()
  • c) lower()
  • d) tolower()

a) strtolower()

25: What is the purpose of the PHP function “session_destroy()”?

  • a) Starts a new session
  • b) Destroys all session variables
  • c) Deletes a specific session variable
  • d) Resets the session ID

Answer: b)

26: Which PHP function is used to count the number of elements in an array?

  • a) array_count()
  • b) array_length()
  • c) count()
  • d) length()

c) count()

27: What is the output of the following PHP code: echo pow(2, 3); ?

  • a) 6
  • b) 8
  • c) 16
  • d) 23

b) 8

28: Which of the following is the correct way to declare a PHP class?

  • a) class MyClass { }
  • b) MyClass = new class { }
  • c) define MyClass { }
  • d) new MyClass { }

a) class MyClass { }

29: Which PHP function is used to delete a specific cookie?

  • a) delete_cookie()
  • b) remove_cookie()
  • c) unset_cookie()
  • d) setcookie()

c) unset_cookie()

30: What is the output of the following PHP code: echo “10” + 5; ?

  • a) 15
  • b) 105
  • c) “105”
  • d) Error

a) 15

Advance PHP MCQs

31: Which of the following is used to check if a variable is an array in PHP?

  • a) isarray()
  • b) is_array()
  • c) isArray()
  • d) check_array()

b) is_array()

32: What is the purpose of the PHP function “mysqli_query()”?

  • a) Executes a MySQL query
  • b) Executes a MongoDB query
  • c) Executes a PostgreSQL query
  • d) Executes a SQLite query

a) Executes a MySQL query

33: What is the correct way to include an external PHP file?

  • a) include(“file.php”);
  • b) import(“file.php”);
  • c) require(“file.php”);
  • d) load(“file.php”);

c) require(“file.php”);

34: What is the output of the following PHP code: echo “Hello” . “World”; ?

  • a) HelloWorld
  • b) Hello World
  • c) HelloWorld
  • d) Error

b) Hello World

35: Which PHP function is used to format a number with a specific number of decimal places?

  • a) format_number()
  • b) number_format()
  • c) decimal_format()
  • d) format_decimal()

b) number_format()

36: What is the purpose of the PHP function “array_push()”?

  • a) Removes an element from an array
  • b) Adds an element to the end of an array
  • c) Reverses the order of elements in an array
  • d) Checks if an element exists in an array

Answer: b)

37: What is the output of the following PHP code: echo strpos(“Hello World”, “o”); ?

  • a) 4
  • b) 7
  • c) 9
  • d) 11

a) 4

38: Which PHP function is used to redirect the user to the previous page?

  • a) redirect_previous()
  • b) header(“Referer: “)
  • c) previous_page()
  • d) go_back()

b) header(“Referer: “)

39: What is the purpose of the PHP function “mysqli_fetch_assoc()”?

  • a) Fetches a row from a MySQL result set as an associative array
  • b) Fetches a row from a MongoDB result set as an associative array
  • c) Fetches a row from a PostgreSQL result set as an associative array
  • d) Fetches a row from a SQLite result set as an associative array

Answer: a)

40: What is the output of the following PHP code: echo round(3.75); ?

  • a) 3
  • b) 4
  • c) 3.5
  • d) 4.5

b) 4

9:20 PM
Tags

Post a Comment

[facebook]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget