PHP quiz questions

PHP interview questions

  • 1.

    What will be the value of $var?

    $var = 1 / 2;
    1. 0

    2. 0.5

    3. 1

    Answer
  • 2.

    What will be printed?

    $var = '0';
    if ($var) {
        echo 'true';
    } else {
        echo 'false';
    }
    1. true

    2. false

    Answer
  • 3.

    Which of the following is used to declare a constant?

    1. const

    2. constant

    3. define

    4. #pragma

    5. def

    Answer
  • 4.

    What gets printed?

    $var = 'false';
    if ($var) {
        echo 'true';
    } else {
        echo 'false';
    }
    1. true

    2. false

    Answer
  • 5.

    A value that has no defined value is expressed in PHP with the following keyword:

    1. undef

    2. null

    3. None

    4. There is no such concept in PHP

    Answer
  • 6.

    Which of the following is the way to create comments in PHP?

    1. // commented code to end of line

    2. /* commented code here */

    3. # commented code to end of line

    4. all of the above

    Answer
  • 7.

    What will be printed by the code below?

    <?php
        FUNCTION TEST()
        {
            ECHO "HELLO WORLD!\n";
        }
        test();
    ?>
    1. HELLO WORLD!

    2. nothing

    3. its a compiler error, the code won't run

    4. hello world!

    Answer
  • 8.

    What value is printed for "a" below?

    <?php
        $a = 1;
        function Test()
        {
            echo "a = $a";
        }
        Test();
    ?>
    1. 1

    2. 2

    3. 3

    4. no value

    Answer
  • 9.

    Which of the following can be used to get information sent via get/post method in PHP?

    1. $_REQUEST

    2. $REQUEST

    3. $REQUEST_PAGE

    4. None of the above.

    Answer
  • 10.

    Which of the following magic constant of PHP returns class method name?

    1. _METHOD_

    2. _FILE_

    3. _FUNCTION_

    4. _CLASS_

    Answer
  • 11.

    Which of the following method of Exception class returns array of the backtrace?

    1. getMessage()

    2. getCode()

    3. getTrace()

    4. getTraceAsString()

    Answer
  • 12.

    Which of the following provides the size of the uploaded file in PHP?

    1. $_FILES['file']['tmp_name']

    2. $_FILES['file']['name']

    3. $_FILES['file']['size']

    4. $_FILES['file']['type']

    Answer
  • 13.

    Which of the following is used to access session variables in PHP?

    1. session_start() function

    2. $_SESSION[]

    3. isset() function

    4. session_destroy() function

    Answer
  • 14.

    Which of the following variable is used to generate random numbers using PHP?

    1. srand()

    2. rand()

    3. random()

    4. None of the above.

    Answer
  • 15.

    Which of the following keyword causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating?

    1. break

    2. continue

    Answer
  • 16.

    Which of the following is correct about determine the "truth" of any value not already of the Boolean type?

    1. If the value is an array, it is false if it contains no other values, and it is true otherwise. For an object, containing a value means having a member variable that has been assigned a value.

    2. Valid resources are true (although some functions that return resources when they are successful will return FALSE when unsuccessful).

    3. Don't use double as Booleans.

    4. All of the above.

    Answer
  • 17.

    Which of the following type of variables are sequences of characters, like 'PHP supports string operations.'?

    1. Strings

    2. Arrays

    3. Objects

    4. Resources

    Answer
  • 18.

    Is PHP whitespace sensitive?

    1. true

    2. false

    Answer
  • 19.

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

    1. mysql_connect()

    2. mysql_query()

    3. mysql_close()

    4. None of the above

    Answer
  • 20.

    Which of the following is correct about preg_match() function?

    1. The preg_match() function searches a string specified by string for a string specified by pattern, returning true if the pattern is found, and false otherwise.

    2. The preg_match() function searches throughout a string specified by pattern for a string specified by string. The search is not case sensitive.

    3. The preg_match() function searches string for pattern, returning true if pattern exists, and false otherwise.

    4. None of the above

    Answer

© 2017 QuizBucket.org