PHP MCQ Questions And Answers

11. Which of the following is the correct way to add a comment in PHP code?

  1. //
  2. /**/
  3. #
  4. All of the above

Answer : D
Explanation: In PHP (Hypertext Preprocessor), /**/ can also be used to comment just a single line although it is used for paragraphs. # and // are used only for single-line comments. So, all of the above option is correct.

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

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

Answer : D
Explanation: In PHP, both print and echo are language constructs. Both print and echo 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, both (A) and (B) option is correct.

13. Which of the following function is used to unset a variable in PHP?

  1. unset()
  2. delete()
  3. unlink()
  4. delete()

Answer : A
Explanation: unset() function is used to unset a variable in PHP.

14. Which of the following is not a built-in string function in PHP?

  1. strlen()
  2. strreverse()
  3. str_replace()
  4. strpos()

Answer : B
Explanation: strreverse() function is not a Built-in String functions in PHP.

15. Which of the following is the correct way to create a function in php?

  1. new_function myFunction()
  2. create myFunction()
  3. function myFunction()
  4. None of the mentioned

Answer : C
Explanation: The declaration of a user-defined function in PHP (Hypertext Preprocessor) starts with the word function, followed by the name of the function you want to create followed by parentheses i.e. () and finally place the function’s code between curly brackets {}. PHP functions are also similar to functions of any other programming languages. A function is a piece of code that takes one or more input in the form of a parameter and does some processing and returns a value. There are built-in functions but PHP gives you the option to create your own functions as well.

Data Science MCQ Questions and Answers

16. Which of the following is the correct way to create an array in PHP?

  1. $season = array(“mango” , “orange” , “banana” , “apple”);
  2. $season = array[“mango” , “orange” , “banana” , “apple”];
  3. $season = “mango” , “orange” , “banana” , “apple”;
  4. All of the mentioned

Answer : A
Explanation: $season = array(“mango” , “orange” , “banana” , “apple”); is the correct way to create an array in PHP.

17. Which of the following function displays the information about PHP and its configuration?

  1. phpinfo()
  2. php_info()
  3. info()
  4. None of the mentioned

Answer : A
Explanation: The phpinfo() function displays the information about the PHP configuration and installation in our system. The phpinfo() function is generally used to check and display the configuration settings.

18. Which of the following function in PHP returns a text in title case from a variable?

  1. toUpper($var)
  2. ucword($var)
  3. ucwords($var)
  4. All of the mentioned

Answer : C
Explanation: The ucwords() is an in-built function of PHP, which is used to convert the first character of each word to uppercase in a string. It takes a string as an input and converts the first character of each word of the string to uppercase. The other characters of the string remain the same. So, option C is correct.

19. Which of the following function returns the number of characters in a string variable in PHP?

  1. count($variable)
  2. strlen($variable)
  3. len($variable)
  4. strcount($variable)

Answer : B
Explanation: strlen($variable) function returns the number of characters in a string variable in PHP.

20. Which of the following variable is not a predefined variable in PHP?

  1. $get
  2. $ask
  3. $post
  4. $request

Answer : B
Explanation: $ask is not a predefined variable in PHP.

This Post Has One Comment

Leave a Reply