PHP Practice Test: Trivia Quiz

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Mukeshrajput
M
Mukeshrajput
Community Contributor
Quizzes Created: 3 | Total Attempts: 1,020
Questions: 21 | Attempts: 263

SettingsSettingsSettings
PHP Practice Test: Trivia Quiz - Quiz


PHP practice test: a trivia quiz. This server scripting language is commonly used to design interactive WebPages. If you have just started learning about it, this quiz is exactly what you need to refresh your memory. Do you know how to work with the remote file in PHP? This quiz tests you on how to align strings in your algorithm but identifiers as well. Give it a try and see how helpful it will be for you.


Questions and Answers
  • 1. 

    pHP is a widely used ……………. scripting language that is especially suited for web development and can be embedded into HTML.

    • A.

      Open source general purpose

    • B.

      Proprietary general purpose

    • C.

      Open source special purpose

    • D.

      Proprietary special purpose

    Correct Answer
    A. Open source general purpose
    Explanation
    PHP is a widely used scripting language that is especially suited for web development and can be embedded into HTML. It is open source, meaning that it is freely available for anyone to use and modify. It is also a general-purpose language, which means that it can be used for a wide range of applications, not just web development.

    Rate this question:

  • 2. 

    Which of the following variables is not a predefined variable?

    • A.

      $get

    • B.

      $ask

    • C.

      $request

    • D.

      $post

    Correct Answer
    B. $ask
    Explanation
    The variable "$ask" is not a predefined variable. In PHP, predefined variables are variables that are already defined and can be used without any additional declaration. Variables like "$get", "$request", and "$post" are examples of predefined variables in PHP, which are used to retrieve data from the URL, server, and HTTP POST requests respectively. However, "$ask" is not a predefined variable in PHP.

    Rate this question:

  • 3. 

    Given a variable $email containing the string [email protected] which of the following will extract the string example.com?

    • A.

      Strstr($email,”@”);

    • B.

      Strchr($email,”@”);

    • C.

      Substr($email, strops(($email,”@”));

    • D.

      Substr($email, strops(($email,”@”)+1);

    Correct Answer
    D. Substr($email, strops(($email,”@”)+1);
    Explanation
    The correct answer is substr($email, strops(($email,"@")+1). This is because the function strops($email,"@") will return the position of the "@" symbol in the string $email. Adding 1 to this position will give us the starting position of the substring we want to extract. Then, the substr() function will extract the substring starting from that position until the end of the string, giving us "example.com".

    Rate this question:

  • 4. 

    Which of the following will not combine strings $s1 and $s2 into a single string?

    • A.

      $s1+$s2

    • B.

      “{$s1}{$s2}”

    • C.

      $s1.$s2

    • D.

      Implode(‘ ‘, array($s1,$s2))

    Correct Answer
    A. $s1+$s2
    Explanation
    The correct answer is $s1+$s2. This is because the "+" operator in PHP is used for numerical addition, not for string concatenation. In order to combine two strings in PHP, the "." operator should be used. The other options, "{$s1}{$s2}" and implode(' ', array($s1,$s2)), are valid ways to combine strings in PHP.

    Rate this question:

  • 5. 

    The ____ function can be used to compare two strings using a case-insensitive binary algorithm.

    • A.

      Strcmp()

    • B.

      Stricmp()

    • C.

      Strcasecmp()

    • D.

      Stristr()

    • E.

      None

    Correct Answer
    C. Strcasecmp()
    Explanation
    The strcasecmp() function can be used to compare two strings using a case-insensitive binary algorithm. This means that the function will compare the strings without considering the difference between uppercase and lowercase letters. This is useful when you want to compare strings without being sensitive to the case of the letters.

    Rate this question:

  • 6. 

    A variable $word is set to “HELLO WORLD”, which of the following script returns in title case?

    • A.

      Echo ucwords($word)

    • B.

      Echo ucwords(strtolower($word))

    • C.

      Echo ucfirst($word)

    • D.

      Echo ucfirst(strtolower($word)

    Correct Answer
    B. Echo ucwords(strtolower($word))
    Explanation
    The function ucwords() capitalizes the first letter of each word in a string. In this case, the string "HELLO WORLD" is first converted to lowercase using strtolower(), and then ucwords() is applied to capitalize the first letter of each word, resulting in "Hello World". The other options either capitalize only the first letter of the entire string (ucfirst($word)), or do not convert the string to title case at all.

    Rate this question:

  • 7. 

    The difference between include() and require()

    • A.

      Are different how they handle failure

    • B.

      Both are same in every aspects

    • C.

      Is include() produced a Fatal Error while require results in a Warning

    • D.

      None of above

    Correct Answer
    A. Are different how they handle failure
    Explanation
    The correct answer is that include() and require() are different in how they handle failure. Include() produces a Fatal Error, which means that if the included file is not found or there is an error in the file, the script will stop executing. On the other hand, require() results in a Warning, which means that if the required file is not found or there is an error, the script will continue executing but with a warning message.

    Rate this question:

  • 8. 

    Trace the odd data type.

    • A.

      Floats

    • B.

      Integer

    • C.

      Doubles

    • D.

      Real number

    Correct Answer
    B. Integer
    Explanation
    The odd data type in this list is "integer" because it is the only data type that represents whole numbers without any decimal places. The other data types, such as "floats," "doubles," and "real number," all allow for decimal places in their values.

    Rate this question:

  • 9. 

    Which of the following are valid float values?

    • A.

      4.5678

    • B.

      4.0

    • C.

      7e4

    • D.

      All of above

    Correct Answer
    D. All of above
    Explanation
    All of the given values are valid float values. 4.5678 and 4.0 are decimal numbers, which can be represented as floats. 7e4 is a scientific notation for 7 multiplied by 10 to the power of 4, which is also a valid float value. Therefore, all of the given values are valid float values.

    Rate this question:

  • 10. 

    In pHP string data are

    • A.

      Delimited by single quote

    • B.

      Delimited by double quote

    • C.

      Delimited by

    • D.

      All of above

    Correct Answer
    C. Delimited by
    Explanation
    In PHP, string data can be delimited by single quotes (''), double quotes ("") or even by using the heredoc syntax. Therefore, the correct answer is "delimited by all of the above".

    Rate this question:

  • 11. 

    Casting operator introduced in pHP 6 is

    • A.

      (array)

    • B.

      (int64)

    • C.

      (real) or (double) or (float)

    • D.

      (object)

    Correct Answer
    B. (int64)
    Explanation
    The casting operator (int64) is used in PHP 6 to convert a value to a 64-bit integer. This operator is used when you want to specifically convert a value to a 64-bit integer data type.

    Rate this question:

  • 12. 

    When defining identifier in pHP you should remember that

    • A.

      Identifier are case sensitive. So $result is different than $ result

    • B.

      Identifiers can be any length

    • C.

      Both of above

    • D.

      None of above

    Correct Answer
    C. Both of above
    Explanation
    When defining an identifier in PHP, it is important to remember that identifiers are case sensitive. This means that $result is considered different than $ result. Additionally, identifiers can be of any length. Therefore, the correct answer is that both of these statements are true.

    Rate this question:

  • 13. 

    The output of following script would be $somerar=15; function ad it () { GLOBAL $somevar; $somerar++ ; echo "somerar is $somerar"; } addit ();

    • A.

      Somerar is 15

    • B.

      Somerar is 16

    • C.

      Somerar is 1

    • D.

      Somerar is $ somerar

    Correct Answer
    B. Somerar is 16
    Explanation
    The output of the script would be "somerar is 16". This is because the script defines a global variable $somerar with a value of 15. Then, a function called addit() is defined, which increments the value of $somerar by 1 and echoes the result. Finally, the addit() function is called, resulting in the value of $somerar being incremented to 16 and echoed.

    Rate this question:

  • 14. 

    Which of the following method sends input to a script via a URL?

    • A.

      Get

    • B.

      Post

    • C.

      Both

    • D.

      None

    Correct Answer
    A. Get
    Explanation
    The correct answer is "Get". The Get method is used to send input to a script via a URL. It appends the input data to the URL as query parameters, allowing the data to be visible in the URL itself. This method is commonly used for retrieving data from a server or fetching web pages.

    Rate this question:

  • 15. 

    Which of the following method is suitable when you need to send larger form submissions?

    • A.

      Get

    • B.

      Post

    • C.

      Both Get and Post

    • D.

      There is no direct way for larger form. You need to store them in a file and retrieve

    Correct Answer
    B. Post
    Explanation
    The Post method is suitable when you need to send larger form submissions. Unlike the Get method, which appends form data to the URL, the Post method sends the data in the body of the HTTP request. This allows for larger amounts of data to be sent securely and efficiently. Therefore, the Post method is the recommended choice for sending larger form submissions.

    Rate this question:

  • 16. 

    The function setcookie( ) is used to

    • A.

      Enable or disable cookie support

    • B.

      Declare cookie variables

    • C.

      Store data in cookie variable

    • D.

      All of above

    Correct Answer
    C. Store data in cookie variable
    Explanation
    The function setcookie() is used to store data in a cookie variable. It allows the programmer to set a cookie with a specified name, value, expiration time, path, and domain. This function enables the server to send a cookie to the client's browser, which can then be stored and later sent back to the server with subsequent requests. This allows the server to remember information about the user, such as their preferences or login status. Therefore, the correct answer is "Store data in cookie variable".

    Rate this question:

  • 17. 

    To work with remote files in pHP you need to enable.

    • A.

      Allow_url_fopen

    • B.

      Allow_remote_files

    • C.

      Both of above

    • D.

      None of above

    Correct Answer
    A. Allow_url_fopen
    Explanation
    To work with remote files in PHP, you need to enable the "allow_url_fopen" option. This option allows PHP to open and read files from remote locations using URLs. By enabling this option, you can use functions like file_get_contents() or fopen() to access and manipulate remote files. The "allow_remote_files" option is not a valid option in PHP, so the correct answer is "allow_url_fopen".

    Rate this question:

  • 18. 

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

    • A.

      Count($variable)

    • B.

      Len($variable)

    • C.

      Strcount($variable)

    • D.

      Strlen($variable)

    Correct Answer
    D. Strlen($variable)
    Explanation
    The function strlen($variable) is used to return the number of characters in a string variable. It calculates and returns the length of the string, which represents the number of characters in the string. This function is commonly used in programming to determine the length of a string and perform operations based on that length.

    Rate this question:

  • 19. 

    The left associative dot operator (.) is used in pHP for

    • A.

      Multiplication

    • B.

      Concatenation

    • C.

      Separate object and its member

    • D.

      Delimeter

    Correct Answer
    B. Concatenation
    Explanation
    The left associative dot operator (.) is used in PHP for concatenation. It is used to combine two strings together to create a new string. This operator allows you to join multiple strings or string variables into a single string. For example, if you have two variables $str1 = "Hello" and $str2 = "World", using the dot operator like $str1 . $str2 will result in the string "HelloWorld".

    Rate this question:

  • 20. 

    Which of the following variable assignments is 'by value' assignment in pHP.

    • A.

      $value1= $value?

    • B.

      $value1= & $value?

    • C.

      $value1= & $value?

    • D.

      None

    Correct Answer
    A. $value1= $value?
    Explanation
    The correct answer is $value1= $value. In PHP, a 'by value' assignment means that the value of the variable is copied to another variable. In this case, the value of $value is being assigned to $value1, creating a new variable with the same value. The other options involve passing the variable by reference, indicated by the use of the ampersand (&) symbol, which means that both variables will refer to the same memory location.

    Rate this question:

  • 21. 

    Which of the following functions require the allow-url-fopen must be enabled?

    • A.

      Include()

    • B.

      Require()

    • C.

      Both of above

    • D.

      None of above

    Correct Answer
    C. Both of above
    Explanation
    The functions include() and require() both require the allow-url-fopen to be enabled. These functions are used to include files in PHP scripts. When allow-url-fopen is enabled, these functions can include files from remote URLs as well. If allow-url-fopen is disabled, including files from remote URLs will not be possible. Therefore, both of these functions require the allow-url-fopen to be enabled.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jul 04, 2013
    Quiz Created by
    Mukeshrajput
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.