PHP Conditional Statements Quiz

Best of Luck


Question 1.

Which of the following statements are conditional statements?

  • A) If statements
  • B) If else statements
  • C) Switch statements
  • D) All of the Above
Question 2.

What will be the output of the following code?

$x = "hello";
if (strlen($x))
    print strlen($x);
else
    print "bye";
  • A) 3
  • B) Hello
  • C) bye
  • D) None of these
Question 3.

What will be the output of the following code?

$val = 20;

  if ($val)

  {

    echo "Hello";

  }

  else

  {

     echo "Hii";

  }

  • A) Hello
  • B) Hi
  • C) Error
  • D) None of these
Question 4.

What will be the output of the following code?

$val = 0;

  if ($val==1) 

       if($val >= 0)

       print “true”;

      else

          print “false”;
  • A) True
  • B) False
  • C) Error
  • D) No output
Question 5.

What will be the output of the following code?

$str = "Compe"; 

 if ($str.length) 

  print $str.tition; 

 else 

  print "E-siksha";
  • A) Compe
  • B) tition
  • C) E-siksha
  • D) Competition
Question 6.

What will be the output of the following code?

$x = 22;
if ($x-- - --$x - $x)
  print "E-siksha";

else
    print "E-siksha Learning Hub";
  • A) 0
  • B) 1
  • C) E-siksha Learning Hub
  • D) E-siksha
Question 7.

What will be the output of the following code?

$i = 25;
$j = 26;

if ($i < ++$i || $j < ++$j)
    print "if statement executed...";

else
    print "else statement executed...";
  • A) else statement executed...
  • B) Error
  • C) if statement executed...
  • D) Nothing
Question 8.

What will be the output of the following code?

$i = 25;
$j = 50;
$k = 15;
if ($i / $j / $k)
    print "E-siksha";
else
    print " E-siksha Learning Hub";
  • A) True
  • B) False
  • C) E-siksha
  • D) E-siksha Learning Hub
Question 9.

What will be the output of the following code?

$x = 150;

if ($x > 25)

    printf("E-siksha");

else if ($x > 35)

    printf("Learning");

else if($x > 45)

    printf("Hub");
  • A) E-siksha
  • B) Learning
  • C) Hub
  • D) All of the Above
Question 10.

What will be the output of the following code?

$i = 11;

if ($i = $i&0)

    print $i;

else

    break;
  • A) 11
  • B) 0
  • C) Error