1. Question: What happens when a form submitted to a PHP script contains two elements with the same name?

    A
    They are combined in an array and stored in the appropriate superglobal array

    B
    The value of the second element is added to the value of the first in the appropriate superglobal array

    C
    The value of the second element overwrites the value of the first in the appropriate superglobal array

    D
    The second element is automatically renamed

    E
    PHP outputs a warning

    Note: PHP simply adds elements to the appropriate superglobal array as they are retrieved from the query string or POST information. As a result, if two elements have the same name, the first one will just be overwritten by the second. Therefore, Answer C is correct.
    1. Report
  2. Question: How would you store an array in a cookie?

    A
    By adding two square brackets ([]) to the name of the cookie

    B
    By using the implode function

    C
    It is not possible to store an array in a cookie due to storage limitations

    D
    By using the serialize function

    E
    By adding the keyword ARRAY to the name of the cookie

    Note: Only Answer B is always correct. While the implode function can be used to convert an array into a string—a prerequisite of being able to store it in a cookie—it cannot guarantee that you’ll be able to reconstruct the array at a later date the way serialize() can. Storing an array in a cookie may not be a good idea because browsers only allow a limited amount of storage space for each cookie, but that’s not always the case—you should be able to store relatively small arrays without much in the way of problems.
    1. Report
  3. Question: What will the following script output?
    <?php
    ob_start();
    for ($i = 0; $i < 10; $i++) {
     echo $i;
    }
    $output = ob_get_contents();
    ob_end_clean();
    echo $ouput;
    ?>

    A
    12345678910

    B
    1234567890

    C
    0123456789

    D
    Nothing

    E
    A notice

    Note: Yet another question designed to see how well you recognize bugs in a script. Did you notice that, at the end of the script, the $output variable’s name is misspelled in the echo statement? The script will output a notice and, therefore, Answer E is correct.
    1. Report
  4. Question: By default, PHP stores session data in _______.

    A
    The filesystem

    B
    A database

    C
    Virtual memory

    D
    Shared memory

    E
    None

    Note: The filesystem (Answer A). By default, PHP stores all session information in the /tmp folder; users of operating systems where this folder doesn’t exist (such as Windows) must change the default value of the session.save_path php.ini setting to a directory appropriate for their setup (e.g.: C:\Temp).
    1. Report
  5. Question: When you write a cookie with an expiration date in the future to a particular machine, the cookie never seem to be set. The technique usually works with other computers, and you have checked that the time on the machine corresponds to the time on the server within a reasonable margin by verifying the date reported by the operating system on the client computer’s desktop. The browser on the client machine seems to otherwise work fine on most other websites. What could be likely causes of this problem? (Choose 2)

    A
    The browser’s binaries are corrupt

    B
    The client machine’s time zone is not set properly

    C
    The user has a virus-scanning program that is blocking all secure cookie

    D
    The browser is set to refuse all cookies

    E
    The cookie uses characters that are discarded all data from your server

    Note: Answers A and D both describe likely causes of this type of problem and warrant further investigation on your part. Since the browser seems to work fine, it’s unlikely that its binaries have suffered corruption such that only your site has stopped working, and virus scanning programs do not normally stop secure cookies selectively (although some block all cookies). On the other hand, the browser might have been explicitly set to refuse all cookies, which is probably the first source of trouble you should check for. By the same token, the computer’s time zone might have been set incorrectly and, since cookie expiration dates are coordinated through GMT, cause the cookie to expire as soon as it was set and never be returned to your scripts.
    1. Report
  6. Question: Assuming that the client browser is never restarted, how long after the last access will a session “expire” and be subject to garbage collection?

    A
    After exactly 1,440 seconds

    B
    After the number of seconds specified in the session.gc_maxlifetime INI setting

    C
    It will never expire unless it is manually deleted

    D
    It will only expire when the browser is restarted

    E
    None

    Note: The session.gc_maxlifetime INI setting regulates the amount of time since the last access after which the session handler considers a session data file “garbage” and marks it for deletion by the garbage handler. Once this has happened, any subsequent access to the session will be considered invalid, even if the data file still exists. Coincidentally, the session.gc_maxlifetime is set to 1,440 seconds, but you can’t rely on that number as it might have been changed without your knowledge by the system administrator. Answer B is, therefore, correct.
    1. Report
  7. Question: The _____ function automatically transforms newline characters into HTML <br /> tags Your Answer: _______

    A
    This identifies the nl2br function, which can be used precisely for this purpose.

    B
    This identifies the nltobr function, which can be used precisely for this purpose.

    C
    This identifies the nl_to_br function, which can be used precisely for this purpose.

    D
    This identifies the nl_br function, which can be used precisely for this purpose.

    E
    none

    Note: Not available
    1. Report
  8. Question: Array values are keyed by ______ values (called indexed arrays) or using ______ values (called associative arrays). Of course, these key methods can be combined as well.

    A
    Float, string

    B
    Positive number, negative number

    C
    Even number, string

    D
    String, Boolean

    E
    Integer, string

    Note: Arrays that are keyed by integer values are called indexed arrays, while those keyed by strings are called associative arrays. The correct answer is, therefore, E.
    1. Report
  9. Question: Consider the following array, called $multi_array. How would the value cat be referenced within the $multi_array array?
    <?php
    $multi_array = array("red",
                                     "green",
                                      42 => "blue",
                                      "yellow" => array("apple",  
                                                                   9 => "pear",  
                                                                   "banana",  
                                                                   "orange" => array("dog", "cat", "iguana")
                                                         )
                                       );
    ?>

    A
    $multi_array['yellow']['apple'][0]

    B
    $multi_array['blue'][0]['orange'][1]

    C
    $multi_array[3][3][2]

    D
    $multi_array['yellow']['orange']['cat']

    E
    $multi_array['yellow']['orange'][1]

    Note: The value cat is in an array buried within two other arrays. Following the path to the string, we see that, first, the yellow key must be referenced, followed by orange. Since the final array is an indexed array, the string cat is the second value and, therefore, has an index key of 1. Therefore, the correct answer is E.
    1. Report
  10. Question: What will the $array array contain at the end of the execution of the following script?
    <?php
    $array = array ('1', '1');
    foreach ($array as $k => $v) {
      $v = 2;
    }
    ?>

    A
    array ('2', '2')

    B
    array ('1', '1')

    C
    array (2, 2)

    D
    array (Null, Null)

    E
    array (1, 1)

    Note: Answer B is correct. The foreach construct operates on a copy of $array and, therefore, no changes are made to its original values.
    1. Report
Copyright © 2024. Powered by Intellect Software Ltd