PHP quiz questions

PHP interview questions

  • 1.

    The PHP syntax is most similar to:

    1. Perl and C

    2. VBScript

    3. JavaScript

    Answer
  • 2.

    What is the correct way to end a PHP statement?

    1. </php>

    2. ;

    3. New line

    4. .

    Answer
  • 3.

    All variables in PHP start with which symbol?

    1. $

    2. !

    3. &

    Answer
  • 4.

    How do you write "Hello World" in PHP

    1. "Hello World";

    2. echo "Hello World";

    3. Document.Write("Hello World");

    Answer
  • 5.

    PHP server scripts are surrounded by delimiters, which?

    1. <&>...</&>

    2. <?php...?>

    3. <?php>...</?>

    4. <script>...</script>

    Answer
  • 6.

    Which statement about the code below is correct?

    class A {}
    class B {}
    class C extends A, B {}
    1. the code is perfectly fine

    2. classes can not be empty

    3. class C can not extend both A and B

    4. qualifiers 'public' or 'private' are missing in class definitions

    Answer
  • 7.

    What gets printed?

    $str = 'a\\b\n'; 
    echo $str;
    1. ab(newline)

    2. a\b(newline)

    3. a\b\n

    4. a\\b(newline)

    5. a\\b\n

    Answer
  • 8.

    What will be printed by the below code?

    $a = 1;
    {
      $a = 2;
    }
    echo $a, "\n";
    1. 1

    2. 2

    Answer
  • 9.

    What will be printed?

    $a = array();
    if ($a[1]) null;
    echo count($a), "\n";
    1. 0

    2. 1

    3. 2

    4. this code won't work

    Answer
  • 10.

    What gets printed?

    class MyException extends Exception {}
    try {
      throw new MyException('Oops!');
    } catch (Exception $e) {
      echo "Caught Exception\n";
    } catch (MyException $e) {
      echo "Caught MyException\n";
    }
    1. Caught Exception

    2. Caught MyException

    Answer
  • 11.

    What will be printed?

    $a = array(
      null => 'a',
      true => 'b',
      false => 'c',
      0 => 'd',
      1 => 'e',
      '' => 'f'
    );
    echo count($a), "\n";
    1. 2

    2. 3

    3. 4

    4. 5

    5. 6

    Answer
  • 12.

    What will be printed?

    $var = 'a';
    $VAR = 'b';
    echo "$var$VAR";
    1. aa

    2. bb

    3. ab

    Answer
  • 13.

    Which of the following is NOT a valid PHP comparison operator?

    1. !=

    2. >=

    3. &&&

    4. <>

    5. ===

    Answer
  • 14.

    What will be printed?

    if ('2' == '02') {   
      echo 'true';
    } else {
      echo 'false';
    }
    1. true

    2. false

    Answer
  • 15.

    What will be the value of $var below?

    $var = true ? '1' : false ? '2' : '3';
    1. 1

    2. 2

    3. 3

    Answer
  • 16.

    What gets printed?

    <?php
    $RESULT = 11 + 011 + 0x11;
    echo "$RESULT";
    ?>
    1. 11

    2. 22

    3. 33

    4. 37

    5. 39

    Answer
  • 17.

    What will be printed?

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

    2. false

    3. there is a syntax error

    Answer
  • 18.

    What will be printed?

    $a = array();
    if ($a == null) { 
      echo 'true';
    } else {
      echo 'false';
    }
    1. true

    2. false

    Answer
  • 19.

    Which of the following is NOT a magic predefined constant?

    1. __LINE__

    2. __FILE__

    3. __DATE__

    4. __CLASS__

    5. __METHOD__

    Answer
  • 20.

    How do we access the value of 'd' later?

    $a = array(
        'a',
        3 => 'b',
        1 => 'c',
        'd'
    );
    1. $a[0]

    2. $a[1]

    3. $a[2]

    4. $a[3]

    5. $a[4]

    Answer

© 2017 QuizBucket.org