Last Website D Test Ever

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 Trunkz0r
T
Trunkz0r
Community Contributor
Quizzes Created: 3 | Total Attempts: 1,459
Questions: 28 | Attempts: 266

SettingsSettingsSettings
Last Website D Test Ever - Quiz

Website developers have become some of the most looked out people in the world today. Whether a developer or a user, it is important to know how to gauge a good website. The quiz below tests on several website concepts.


Questions and Answers
  • 1. 

    7. To delete a cookie, you

    • A.

      A. delete the $_COOKIE variable

    • B.

      B. use the delete_cookie function

    • C.

      C. use the remove_cookie function

    • D.

      D. set the cookie’s value to an empty string and its expiration date to a time in the past

    Correct Answer
    D. D. set the cookie’s value to an empty string and its expiration date to a time in the past
    Explanation
    To delete a cookie, you set the cookie's value to an empty string and its expiration date to a time in the past. This effectively removes the cookie from the user's browser as it will no longer have any value and will be considered expired. The browser will then automatically remove the cookie from its storage.

    Rate this question:

  • 2. 

    8. When you use session tracking, each HTTP request includes

    • A.

      A. a URL that stores the session ID

    • B.

      B. a cookie that stores the session ID

    • C.

      C. a cookie that stores the session data

    • D.

      D. a cookie that stores the session ID and the session data

    Correct Answer
    B. B. a cookie that stores the session ID
    Explanation
    When you use session tracking, each HTTP request includes a cookie that stores the session ID. This cookie is used to identify the user's session on the server. By including the session ID in a cookie, the server can associate subsequent requests from the same client with the correct session. This allows the server to maintain stateful information for the user across multiple requests. Therefore, option b is the correct answer.

    Rate this question:

  • 3. 

    9. The $_SESSION variable for a session

    • A.

      A. is a regular array

    • B.

      B. is an associative array

    • C.

      C. is an object

    • D.

      D. is a cookie

    Correct Answer
    B. B. is an associative array
    Explanation
    The $_SESSION variable for a session is an associative array. This means that it is a type of array where each element is identified by a unique key instead of a numerical index. In the case of $_SESSION, the keys are the names of the session variables, and the values are the data stored in those variables. This allows for easy access and manipulation of session data in PHP.

    Rate this question:

  • 4. 

    10. If necessary, you can use PHP functions to do all but one of the following. Which one is it?

    • A.

      A. get the name of the session cookie

    • B.

      B. get the session ID

    • C.

      C. generate a new session ID

    • D.

      D. get the data for a session ID

    Correct Answer
    D. D. get the data for a session ID
    Explanation
    PHP functions can be used to get the name of the session cookie (option a), get the session ID (option b), and generate a new session ID (option c). However, getting the data for a session ID (option d) requires accessing the session data through other means, such as using session variables or session superglobal arrays.

    Rate this question:

  • 5. 

    11. The function that follows returns   function coin_toss() {    if (mt_rand(0, 1) == 0) {    $coin = 'heads';    } else {    $coin = 'tails';    }    return $coin;   }

    • A.

      A. a random value between 0 and 1

    • B.

      B. a value of either 0 or 1

    • C.

      C. a value of either “heads” or “tails”

    • D.

      D. a reference to the $coin variable

    Correct Answer
    C. C. a value of either “heads” or “tails”
    Explanation
    The given function coin_toss() uses the mt_rand() function to generate a random number between 0 and 1. If the generated number is 0, it assigns the value "heads" to the variable $coin, otherwise it assigns the value "tails". Finally, it returns the value of $coin. Therefore, the function returns a value of either "heads" or "tails".

    Rate this question:

  • 6. 

    All of the arguments that are passed to a function are available in an array that can be accessed   by using the

    • A.

      A. $_ARGUMENTS variable

    • B.

      B. $_FUNCTION variable

    • C.

      C. func_get_args function

    • D.

      D. func_num_args function

    Correct Answer
    C. C. func_get_args function
    Explanation
    The correct answer is c. func_get_args function. This function allows access to all the arguments passed to a function by returning them as an array. The $_ARGUMENTS and $_FUNCTION variables do not exist in PHP, and the func_num_args function only returns the number of arguments passed, not the actual arguments themselves.

    Rate this question:

  • 7. 

    13. If you create a function that passes an argument by reference, the function

    • A.

      A. can change the original variable without using a return statement

    • B.

      B. can change the variable and pass it back by using a return statement

    • C.

      C. can’t change the variable

    • D.

      D. must make a copy of the variable before it changes it

    Correct Answer
    A. A. can change the original variable without using a return statement
    Explanation
    When a function passes an argument by reference, it means that the function can directly modify the original variable that was passed as an argument. This is done without needing to use a return statement to pass the modified variable back to the calling code. Therefore, option a. is correct as it states that the function can change the original variable without using a return statement.

    Rate this question:

  • 8. 

    14. In PHP, function name duplications are likely to occur because

    • A.

      A. namespaces create logical function groups

    • B.

      B. all the functions for an application have to be stored in the same file

    • C.

      C. all functions have global scope

    • D.

      D. most programmers use the same naming conventions for functions

    Correct Answer
    C. C. all functions have global scope
    Explanation
    In PHP, function name duplications are likely to occur because all functions have global scope. This means that functions can be accessed and called from anywhere in the code, leading to a higher chance of naming conflicts. If multiple functions with the same name are defined in different parts of the code, it can cause confusion and unexpected behavior. It is good practice to use unique and descriptive names for functions to avoid such conflicts.

    Rate this question:

  • 9. 

    15. To avoid the duplication of function names, you can

    • A.

      Use namespaces

    • B.

      B. Use libraries

    • C.

      C. Store function files in lower-level directories

    • D.

      D. Use include paths

    Correct Answer
    A. Use namespaces
    Explanation
    To avoid the duplication of function names, using namespaces is an effective solution. Namespaces provide a way to group related functions, classes, and variables under a specific name, ensuring that they do not clash with similar names in other parts of the codebase. This helps in organizing and managing code, preventing naming conflicts, and improving code reusability. By using namespaces, developers can differentiate between functions with the same name by specifying the namespace they belong to, thus eliminating duplication and enhancing code clarity and maintainability.

    Rate this question:

  • 10. 

    11. To prevent other classes from directly accessing the properties of a class, you can code them as    private. Then, to make them available to other classes, you can code

    • A.

      A. private methods to set and get their values

    • B.

      B. public methods to set and get their values

    • C.

      C. a constructor to set and get their values

    • D.

      D. a destructor to set and get their values

    Correct Answer
    B. B. public methods to set and get their values
    Explanation
    To prevent other classes from directly accessing the properties of a class, the properties can be coded as private. However, to make them available to other classes, public methods need to be coded to set and get their values. By using public methods, other classes can access and modify the values of the private properties indirectly, ensuring encapsulation and data integrity.

    Rate this question:

  • 11. 

    When you use object-oriented techniques to implement the MVC pattern, the methods of the   model return the data as either arrays or

    • A.

      A. classes

    • B.

      B. objects

    • C.

      C. properties

    • D.

      D. result sets

    Correct Answer
    B. B. objects
    Explanation
    When using object-oriented techniques to implement the MVC pattern, the methods of the model return the data as objects. Objects are instances of classes and they encapsulate both data and behavior. By returning data as objects, the model can provide a more structured and organized way of representing and manipulating the data, allowing for easier integration and interaction with other components of the MVC architecture.

    Rate this question:

  • 12. 

    When a new class extends a superclass, it inherits the properties and methods of the superclass.   Then, it can

    • A.

      A. override the inherited properties

    • B.

      B. override the inherited methods

    • C.

      C. delete any of the inheritied properties

    • D.

      D. delete any of the inherited methods

    Correct Answer
    B. B. override the inherited methods
    Explanation
    When a new class extends a superclass, it inherits the properties and methods of the superclass. This means that the new class can access and use these properties and methods without having to redefine them. However, if the new class wants to change the behavior of a method that it inherited from the superclass, it can override that method. By overriding a method, the new class provides its own implementation of the method, which will be used instead of the implementation in the superclass. This allows the new class to customize the behavior of the inherited method to better suit its own needs. Therefore, the correct answer is b. override the inherited methods.

    Rate this question:

  • 13. 

    To code a constructor for a class named Cart that requires two arguments, you start with this code:

    • A.

      A. public function Cart($arg1, $arg2) {

    • B.

      B. public function __construct($arg1, $arg2) {

    • C.

      C. private function Cart($arg1, $arg2) {

    • D.

      D. private function __construct($arg1, $arg2) {

    Correct Answer
    B. B. public function __construct($arg1, $arg2) {
    Explanation
    The correct answer is b. public function __construct($arg1, $arg2) { because in PHP, the constructor for a class is defined using the __construct keyword. This code snippet shows the correct syntax for creating a constructor for the Cart class that requires two arguments, $arg1 and $arg2. The public access modifier indicates that the constructor can be accessed from outside the class.

    Rate this question:

  • 14. 

    15. To create an object from a class named Cart that requires two arguments, you code

    • A.

      A. new Cart($arg1, $arg2)

    • B.

      B. new Cart(arg1, arg2)

    • C.

      C. Cart_constructor($arg1, $arg2)

    • D.

      D. Cart_constructor(arg1, arg2)

    Correct Answer
    A. A. new Cart($arg1, $arg2)
    Explanation
    To create an object from a class named Cart that requires two arguments, the correct way to code it is by using the "new" keyword followed by the class name and passing the arguments within parentheses. In this case, the arguments are represented as $arg1 and $arg2. Therefore, the correct code would be "new Cart($arg1, $arg2)".

    Rate this question:

  • 15. 

         9.   Which function searches for a regular expression in a string and returns 1 if the pattern is found?

    • A.

      A. match_preg

    • B.

      B. preg_match

    • C.

      C. search_preg

    • D.

      D. preg_search

    Correct Answer
    B. B. preg_match
    Explanation
    The function preg_match is used to search for a regular expression in a string and returns 1 if the pattern is found.

    Rate this question:

  • 16. 

    If a match is found in a global search for a regular expression, the function returns

    • A.

      True

    • B.

      1

    • C.

      C. A count of the number of matches

    • D.

      A count of the number of matches and an array that contains all of the matches

    Correct Answer
    D. A count of the number of matches and an array that contains all of the matches
    Explanation
    If a match is found in a global search for a regular expression, the function returns a count of the number of matches and an array that contains all of the matches. This means that the function not only provides information about the number of matches found, but also provides the actual matches themselves in an array format.

    Rate this question:

  • 17. 

    If a match is found when the preg_split function is executed, it returns

    • A.

      If a match is found when the preg_split function is executed, it returns

    • B.

      B. An array of all of the matches

    • C.

      C. An array of the substrings that are created by removing the matches

    • D.

      D. A count of the number of matches and an array of substrings

    Correct Answer
    C. C. An array of the substrings that are created by removing the matches
    Explanation
    When the preg_split function is executed and a match is found, it returns an array of the substrings that are created by removing the matches. This means that the original string is split into multiple substrings at the locations where the matches are found, and these substrings are stored in an array. The matches themselves are not included in the resulting array.

    Rate this question:

  • 18. 

       12.   Regular expressions can be used to 

    • A.

      A. completely validate all types of user entries

    • B.

      B. only to check whether user entries have the right format

    • C.

      C. completely validate some types of user entries

    • D.

      D. are limited to the validation of string data

    Correct Answer
    D. D. are limited to the validation of string data
    Explanation
    Regular expressions are a powerful tool for pattern matching and manipulating string data. They can be used to validate whether a given string matches a specific pattern or format. However, they are limited to the validation of string data only and cannot be used to validate other types of user entries such as numbers, dates, or email addresses. Therefore, option d is the correct answer as it accurately states the limitation of regular expressions to the validation of string data.

    Rate this question:

  • 19. 

       13.   To get the message that’s related to an exception, you use the 

    • A.

      A. message property of the exception object

    • B.

      B. getMessage method of the exception object

    • C.

      C. message property of the exception class

    • D.

      D. getMessage property of the exception class

    Correct Answer
    B. B. getMessage method of the exception object
    Explanation
    The correct answer is b. getMessage method of the exception object. This method is used to retrieve the message associated with an exception object. It returns a string that provides information about the exception that occurred.

    Rate this question:

  • 20. 

    An exception is thrown when 

    • A.

      A. a runtime error occurs in a try block

    • B.

      B. a runtime error is caught by a catch block

    • C.

      C. PHP encounters invalid data

    • D.

      D. a runtime error occurs

    Correct Answer
    D. D. a runtime error occurs
    Explanation
    When a runtime error occurs, the program encounters an exceptional situation that it cannot handle. As a result, an exception is thrown, indicating that an error has occurred. This allows the program to transfer control to an appropriate catch block, where the error can be handled or logged. The other options (a, b, and c) are not accurate explanations for when an exception is thrown.

    Rate this question:

  • 21. 

                This pattern can be used to validate a five-digit zip code:

    • A.

      A. /[d5]/

    • B.

      B. /+\d[5]?/

    • C.

      C. /^\d{5}$/

    • D.

      D. /$\d5^/

    Correct Answer
    C. C. /^\d{5}$/
    Explanation
    The correct answer is c. /^\d{5}$/.


    This regular expression pattern uses the caret (^) and dollar sign ($) anchors to match exactly five digits. The \d represents any digit, and the {5} quantifier specifies that there should be exactly five occurrences of the preceding digit. The ^ at the beginning ensures that the pattern starts at the beginning of the string, and the $ at the end ensures that it ends at the end of the string. Therefore, this pattern will only match strings that consist of exactly five digits, which is the format of a five-digit zip code.

    Rate this question:

  • 22. 

    9. Which of the following statements about associative arrays is NOT true?

    • A.

      A. You can use the count function to return the number of elements in the array.

    • B.

      B. You can use both integer and string indexes with an associative array.

    • C.

      C. You can use a foreach loop to access the values of an associative array but not the indexes

    • D.

      D. You can delete elements from an associative array.

    Correct Answer
    C. C. You can use a foreach loop to access the values of an associative array but not the indexes
    Explanation
    The given statement is false. In a foreach loop, you can access both the indexes and values of an associative array. The foreach loop iterates over each element in the array, allowing you to access both the key (index) and the value associated with that key. Therefore, option c is not true.

    Rate this question:

  • 23. 

    10. Gaps can be introduced into an array in all of the ways that follow, except one. Which one is it?

    • A.

      A. add a new element with an index that’s beyond the next one that’s available

    • B.

      B. store an empty value in an array

    • C.

      C. delete or unset an element from an array

    • D.

      D. store a NULL value in an array

    Correct Answer
    B. B. store an empty value in an array
    Explanation
    Gaps can be introduced into an array by adding a new element with an index that’s beyond the next one that’s available, deleting or unsetting an element from an array, and storing a NULL value in an array. However, storing an empty value in an array does not introduce a gap, as the element still exists in the array with an empty value.

    Rate this question:

  • 24. 

    11. You can deal with gaps in an array in all but one of the following ways. Which one is it?

    • A.

      A. Use the array_values function to remove all gaps and re-index the array.

    • B.

      B. Use a foreach loop to process the array, which skips elements that contain nulls.

    • C.

      C. Use a for loop that contains extra code that skips elements that contain nulls.

    • D.

      D. Use the array_fill function to replace all gaps in the array with empty strings.

    Correct Answer
    D. D. Use the array_fill function to replace all gaps in the array with empty strings.
    Explanation
    The correct answer is d. Using the array_fill function to replace all gaps in the array with empty strings. This is the only option that specifically addresses filling the gaps in the array with empty strings. The other options either remove the gaps or skip the elements that contain nulls, but they don't explicitly fill the gaps with empty strings.

    Rate this question:

  • 25. 

    Which of the following functions removes the next element in a LIFO array (also known as a stack)?

    • A.

      A. array_shift

    • B.

      B. array_unshift

    • C.

      C. array_push

    • D.

      D. array_pop

    Correct Answer
    D. D. array_pop
    Explanation
    The function array_pop removes the next element in a LIFO array, also known as a stack. In a stack, the last element that was added is the first one to be removed, which is the behavior of the array_pop function. The other options, array_shift, array_unshift, and array_push, do not remove elements from the end of the array, making them incorrect choices for this question.

    Rate this question:

  • 26. 

    The easiest way to add the values in an array is to use

    • A.

      A. a for loop

    • B.

      B. a foreach loop

    • C.

      C. the array_sum function

    • D.

      D. the sum_array function

    Correct Answer
    C. C. the array_sum function
    Explanation
    The array_sum function is the easiest way to add the values in an array because it is a built-in function in many programming languages that allows you to calculate the sum of all the elements in an array with just one line of code. This function eliminates the need for writing a for loop or a foreach loop to iterate through the array and manually add up the values. Therefore, option c is the correct answer.

    Rate this question:

  • 27. 

    14. Which of the following statements about an array of arrays is true?

    • A.

      A. Both indexes in an array of arrays must be integer indexes

    • B.

      B. An associative array can’t be used as an array within another array.

    • C.

      C. All of the arrays within an array must have the same number of elements.

    • D.

      D. You can use both for loops and foreach loops to work with an array of arrays.

    Correct Answer
    D. D. You can use both for loops and foreach loops to work with an array of arrays.
    Explanation
    The correct answer is d. You can use both for loops and foreach loops to work with an array of arrays. This means that you have the flexibility to choose between using a for loop or a foreach loop when working with an array of arrays. Both types of loops can be used to iterate through the elements of the outer array and the inner arrays within it.

    Rate this question:

  • 28. 

       15.   What will the value of the $totals_string variable be after the following code is executed? $totals = array(141.95, 212.95, 411, 10.95); $totals[2] = 312.95; $totals_string = ""; for ($i = 0; $i < count($totals); $i++) {     $totals_string .= $totals[$i] . "|"; }

    • A.

      A. 141.95|312.95|411|10.95|

    • B.

      B. 141.95|212.95|312.95|10.95|

    • C.

      C. 141.95|212.95|411|312.95|

    • D.

      D. 10.95|

    Correct Answer
    B. B. 141.95|212.95|312.95|10.95|
    Explanation
    The code initializes an empty string variable called $totals_string. It then loops through the $totals array and appends each element followed by a "|" to the $totals_string variable. The loop iterates 4 times, so the $totals_string variable will contain the values of the $totals array separated by "|" symbols. Therefore, the correct answer is b. 141.95|212.95|312.95|10.95|.

    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
  • Sep 07, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • May 15, 2014
    Quiz Created by
    Trunkz0r
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.