PHP MCQ Questions And Answers

21. Variable name in PHP starts with

  1. $ (Dollar)
  2. ! (Exclamation)
  3. # (Hash)
  4. & (Ampersand)

Answer : A
Explanation: In Hypertext Preprocessor (PHP), a variable is declared using a Dollar ($) sign followed by the variable name. As we know that PHP is a loosely typed language, so we don’t need to declare the data types of the variables. It automatically analyzes the values and makes conversions to its correct datatype. Variables in PHP (Hypertext Preprocessor) are case-sensitive, so for example, $xyz and $XYZ both are treated as different variables.

22. Among echo and print, which is faster?

  1. print
  2. echo
  3. Can’t say
  4. Both have same speed

Answer : B
Explanation: echo is faster than print.

23. Is php variable case sensitive

  1. False
  2. True

Answer : B
Explanation: Yes, PHP variables are case sensitive.

24. In PHP,  class names as well as function/method names are not case sensitive

  1. True
  2. False

Answer : A
Explanation: In PHP, class names as well as function/method names are not case sensitive, though it is usually good form to call functions as they appear in their declaration.

25. In PHP, Which keyword precedes a method name?

  1. method
  2. public
  3. function
  4. method

Answer : C
Explanation: In PHP, a method declaration resembles a function declaration. The function keyword precedes a method name, followed by an optional list of argument variables in parentheses. So, option C is correct.

26. Which of the following PHP functions accepts any number of parameters?

  1. get_argc()
  2. func_get_argv()
  3. get_argv()
  4. func_get_args()

Answer : D
Explanation: In PHP, func_get_args() functions accepts any number of parameters. func_get_args() returns an array of arguments provided. One can use func_get_args() inside the function to parse any number of passed parameters. So, option D is correct.

27. Which of the following method can be used to create a MySql database using PHP?

  1. mysql_connect()
  2. mysql_close()
  3. mysql_query()
  4. None of the mentioned

Answer : C
Explanation: mysql_query() method can be used to create a MySql database using PHP.

28. Which one of the following is not a valid class name?

  1. ShopProduct
  2. 1shopproduct
  3. Shopproduct1
  4. Shopproduct

Answer : B
Explanation: In PHP, one can declare a class with the class keyword and an arbitrary class name. Class names can be written with any combination of numbers and letters, although they must not begin with a number. So, option B is correct.

29. Which of the following is used to display the output in PHP?

  1. echo
  2. print
  3. write
  4. Both (A) and (B)
  5. Both (A) and (C)

Answer : D
Explanation: In Hypertext Preprocessor (PHP), both “echo” and “print” are language constructs. Both “echo” and “print” statements can be used with or without parentheses. We can use these statements to output variables or strings. The echo is a statement, which is used to display the output. The print is a statement used as an alternative to echo at many times to display the output. So, option D is correct.

30. A function in PHP that starts with _ _ (double underscore) is known as

  1. Magic Function
  2. Inbuilt Function
  3. User Defined Function
  4. Default Function
  5. None of the mentioned

Answer : A
Explanation: In Hypertext Preprocessor (PHP), functions that start with a double underscore ( _ _ ) are called magic functions. They are functions that are always defined inside classes, and are not stand-alone functions. So, option A is correct.

This Post Has One Comment

Leave a Reply