PHP Conditional Statements Aptitude Questions and Answers

PHP Conditional Statements Aptitude Questions and Answers: This section contains aptitude questions and answers on PHP Conditional Statements. By Nidhi Last updated : December 15, 2023

This section contains Aptitude Questions and Answers on PHP Conditional Statements.

1) Which of the following statements are conditional statements in PHP?
  1. If statements
  2. If else statements
  3. Switch statements
  4. Loop statements

Options:

  1. A and B
  2. C
  3. A, B, and C
  4. A, B, C, and D

2) What is the correct output of the given code snippets?
<?php
  $num = 20;
  
  if ($num) 
  {
    echo "Hello";
  }
  else
  {
  	echo "Hii";
  }
?>
  1. Hello
  2. Hi
  3. Error
  4. None of the above

3) What is the correct output of the given code snippets?
<?php
  
  if (echo("India ")) 
  {
    echo "Hello";
  }
  else
  {
  	echo "Hii";
  }
?>
  1. India Hello
  2. India Hii
  3. Error
  4. None of the above

4) What is the correct output of the given code snippets?
<?php
  
  if (print("India ")) 
  {
    echo "Hello";
  }
  else
  {
  	echo "Hii";
  }
?>
  1. India Hello
  2. India Hii
  3. Error
  4. None of the above

5) What is the correct output of the given code snippets?
<?php  
  if (true) 
  {
    echo "Hello";
  }
  else
  {
  	echo "Hii";
  }
?>
  1. Hello
  2. Hii
  3. Error
  4. None of the above

6) What is the correct output of the given code snippets?
<?php  
  if (0) 
  {
    echo "Hello";
  }
  else
  {
  	echo "Hii";
  }
?>
  1. Hello
  2. Hii
  3. Error
  4. None of the above

7) What is the correct output of the given code snippets?
<?php  
  $num1 = 10;
  $num2 = 20;

  if ($num1 > $num2) 
    echo "ABC";
    echo "PQR";
  else
  	echo "XYZ";
?>
  1. ABC PQR
  2. XYZ
  3. Error
  4. None of the above

8) What is the correct output of the given code snippets?
<?php  
  $num1 = 10;
  $num2 = 20;
  $num3 = 30;

  if ($num1 > $num2 && $num1>$num3) 
    echo $num1;
  else if($num2 > $num1 && $num2>$num3) 
  	echo $num2;
  else
  	echo $num3;
?>
  1. 10
  2. 20
  3. 30
  4. Error

9) What is the correct output of the given code snippets?
<?php  
  $num1 = 10;
  $num2 = 20;
  $num3 = 30;

  if ($num1 > $num2 && $num1>$num3) 
    echo $num1;
  elseif($num2 > $num1 && $num2>$num3) 
  	echo $num2;
  else
  	echo $num3;
?>
  1. 10
  2. 20
  3. 30
  4. Error

10) What is the correct output of the given code snippets?
<?php  
  $num1 = 10;
  $num2 = 20;
  $num3 = 30;

  if ($num1 > $num2 and $num1>$num3) 
    echo $num1;
  elseif($num2 > $num1 and $num2>$num3) 
  	echo $num2;
  else
  	echo $num3;
?>
  1. 10
  2. 20
  3. 30
  4. Error

11) What is the correct output of the given code snippets?
<?php  
  if (10 and 20) 
    	echo "ABC";
  elseif(0 and -1) 
  	echo "PQR";
  else
  	echo "XYZ";
?>
  1. ABC
  2. PQR
  3. XYZ
  4. Error

12) What is the correct output of the given code snippets?
<?php  
  if(0 and -1) 
    echo "ABC";
  else if (10 and 20) 
  	echo "PQR";
  else
  	echo "XYZ";
?>
  1. ABC
  2. PQR
  3. XYZ
  4. Error

13) What is the correct output of the given code snippets?
<?php  
  	if(print("ABC ") and print("PQR ")) 
	    echo "TUV";
	else
  	   echo "XYZ";
?>
  1. ABC PQR TUV
  2. ABC PQR XYZ
  3. ABC TUV
  4. ABC XYZ

14) What is the correct output of the given code snippets?
<?php
if (print ("ABC ") or print ("PQR ")) echo "TUV";
else echo "XYZ";
?>
  1. ABC PQR TUV
  2. ABC PQR XYZ
  3. ABC TUV
  4. ABC XYZ

15) What is the correct output of the given code snippets?
<?php
if (print ("ABC ") xor print ("PQR ")) echo "TUV";
else echo "XYZ";
?>
  1. ABC PQR TUV
  2. ABC PQR XYZ
  3. ABC TUV
  4. Error

16) What is the correct output of the given code snippets?
<?php  
  if(print("ABC ") xor print('PQR ')) 
    echo "TUV;
  else
  	echo "XYZ";
?>
  1. ABC PQR TUV
  2. ABC PQR XYZ
  3. ABC TUV
  4. Error

17) What is the correct output of the given code snippets?
<?php
if (true & print ("PQR ")) echo "TUV";
else echo "XYZ";
?>
  1. PQR 1TUV
  2. PQR 0TUV
  3. PQR TUV
  4. None of the above

18) What is the correct output of the given code snippets?
<?php
if (true & true) if (true) echo "ABC";
else echo "PQR";
else echo "XYZ";
?>
  1. ABC
  2. PQR
  3. XYZ
  4. None of the above

19) What is the correct output of the given code snippets?
<?php
switch (1)
{
    case 0:
        echo "ABC ";
    case 1:
        echo "PQR ";
    case 2:
        echo "TUV ";
    default:
        echo "XYZ ";
}
?>
  1. PQR
  2. PQR TUV XYZ
  3. Error
  4. None of the above

20) What is the correct output of the given code snippets?
<?php  
    switch(1)
    {
            default:
        		echo "XYZ ";
            break;
            
            case 0:
        		echo "ABC ";
            break;
            
            case 1:
        		echo "PQR ";
            break;
            
            case 2:
        		echo "TUV ";
            break;
    }
?>
  1. PQR
  2. PQR TUV XYZ
  3. Error
  4. None of the above

21) What is the correct output of the given code snippets?
<?php
switch ('1')
{
    default:
        echo "XYZ ";
    break;
    case 0:
        echo "ABC ";
    break;
    case 1:
        echo "PQR ";
    break;
    case 2:
        echo "TUV ";
    break;
}
?>
  1. PQR
  2. PQR TUV XYZ
  3. Error
  4. None of the above

22) What is the correct output of the given code snippets?
<?php
switch ('1')
{
    default:
        echo "XYZ ";
    break;
    case "0":
        echo "ABC ";
    break;
    case "1":
        echo "PQR ";
    break;
    case "2":
        echo "TUV ";
    break;
}
?>
  1. PQR
  2. PQR TUV XYZ
  3. Error
  4. None of the above

23) What is the correct output of the given code snippets?
<?php
switch ('1')
{
    default:
        echo "XYZ ";
    case 0:
        echo "ABC ";
    break;
    case 1:
        echo "PQR ";
    break;
    case 2:
        echo "TUV ";
    break;
}
?>
  1. PQR
  2. XYZ PQR
  3. Error
  4. None of the above

24) What is the correct output of the given code snippets?
<?php  
    switch(1)
        case 1:
        	echo "PQR ";
        break;
    
?>
  1. PQR
  2. Error

25) What is the correct output of the given code snippets?
<?php
$num = 2;
switch (num)
{
    case 0:
        echo "ABC ";
    break;
    case 1:
        echo "PQR ";
    break;
    case 2:
        echo "TUV ";
    break;
    default:
        echo "XYZ ";
    break;
}
?>
  1. ABC
  2. XYZ
  3. Error
  4. None of the above

Learn PHP programming with our PHP tutorial.

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.