PHP Introduction


  1. What will be the output of the following php code?
    <?php
    $n = "12";
    $n1 = "21";
    print $n+$n1;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    The numbers inside the double quotes are considered as integers and not string, therefore the value 33 is printed and not 12+21.


  1. Which of following variables can be assigned a value to it?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    A variable can’t start with a number. Also $this is a special variable that can’t be assigned, but $This can be assigned.



  1. What will be the output of the following code?
    <?php 
    $name = 'Ajit';
    $temp = &$name;
    $temp = "My name is $temp. ";
    echo $temp;
    echo $name;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    The $temp = &$name; line will reference $name via $temp.


  1. Which of the following PHP statements will output Hello interview Mania on the screen?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    echo(), print() and printf() all three can be used to output a statement onto the screen. The sprintf() statement is functionally identical to printf() except that the output is assigned to a string rather than rendered to the browser.



  1. What will be the output of the following PHP code?
    <?php
    $var = "YELLOW";
    $var1 = $var[5];
    echo "$var1";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    PHP treats strings in the same fashion as arrays, allowing for specific characters to be accessed via array offset notation.