Sail E0 Webinar

MCQs

Total Questions : 26 | Page 1 of 3 pages
Question 1. Which of the following php statement/statements will store 111 in variable num?i) int $num = 111;ii) int mum = 111;iii) $num = 111;iv) 111 = $num;
  1.    Both (i) and (ii)
  2.    All of the mentioned.
  3.    Only (iii)
  4.    Only (i)
 Discuss Question
Answer: Option C. -> Only (iii)


You need not specify the datatype in php.


Question 2. What will be the output of the following php code
< ?php
$num = 1;
$num1 = 2;
print $num . "+". $num1 ;
?>
  1.    3
  2.    1+2
  3.    1.+.2
  4.    Error
 Discuss Question
Answer: Option B. -> 1+2


.(dot) is used to combine two parts of the statement. Example ( $num . "Hello World ) will output 1Hello World.


Question 3. What will be the output of the following code?
< ?php
$foo = 'Bob';
$bar = &$foo;
$bar = "My name is $bar";
echo $bar;
echo $foo;
?>
  1.    Error
  2.    My name is BobBob
  3.    My name is BobMy name is Bob
  4.    My name is Bob Bob
 Discuss Question
Answer: Option C. -> My name is BobMy name is Bob


The $bar = &$foo; line will reference $foo via $bar.


Question 4. What will be the output of the following php code?
< ?php
$num = "1";
$num1 = "2";
print $num+$num1 ;
?>
  1.    3
  2.    1+2
  3.    Error
  4.    12
 Discuss Question
Answer: Option A. -> 3


The numbers inside the double quotes are considered as integers and not string, therefore the value 3 is printed and not 1+2.


Question 5. Which of following variables can be assigned a value to it?(i) $3hello(ii) $_hello(iii) $this(iv) $This
  1.    All of the mentioned
  2.    Only (ii)
  3.    (ii), (iii) and (iv)
  4.    (ii) and (iv)
 Discuss Question
Answer: Option D. -> (ii) and (iv)


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


Question 6. Which of the below statements is equivalent to $add += $add ?
  1.    $add = $add
  2.    $add = $add +$add
  3.    $add = $add + 1
  4.    $add = $add + $add + 1
 Discuss Question
Answer: Option B. -> $add = $add +$add


a += b is an addition assignment whose outcome is a = a + b. Same can be done with subtraction,multiplication,division etc.


Question 7. What will be the output of the following code?
< ?php
function track() {
static $count = 0;
$count++;
echo $count ;
}
track();
track();
track();
?>
  1.    123
  2.    111
  3.    000
  4.    011
 Discuss Question
Answer: Option A. -> 123


Because $count is static, it retains its previous value each time the function is executed.


Question 8. Which statement will output $x on the screen?
  1.    echo \$x";
  2.    echo $$x";
  3.    echo /$x";
  4.    echo $x;
 Discuss Question
Answer: Option B. -> echo $$x";


A backslash is used so that the dollar sign is treated as a normal string character rather than prompt PHP to treat $x as a variable. The backslash used in this manner is known as escape character.


Question 9. What will be the output of the following PHP code?
< ?php
$a = "clue";
$a .= "get";
echo "$a";
?>
  1.    get
  2.    true
  3.    false
  4.    clueget
 Discuss Question
Answer: Option D. -> clueget


.= is a concatenation-assignment. $a equals its current value concatenated with "get.


Question 10. What will be the output of the following PHP code?
< ?php
$team = "arsenal";
switch ($team) {
case "manu":
echo "I love man u";
case "arsenal":
echo "I love arsenal";
case "manc":
echo "I love manc"; }
?>
  1.    I love arsenal
  2.    Error
  3.    I love arsenalI love manc
  4.    I love arsenalI love mancI love manu
 Discuss Question
Answer: Option C. -> I love arsenalI love manc


If a break statement isn't present, all subsequent case blocks will execute until a break statement is located.


Latest Videos

Latest Test Papers