0% found this document useful (0 votes)
247 views26 pages

INT 220 MCQs

The document provides links to multiple choice questions (MCQs) and tests related to PHP basics, variables, control structures, and loops. It includes sample questions and answers on PHP fundamentals like print vs echo, variable scoping and operators, if/else and switch statements, and while/do-while loops.

Uploaded by

Biraj Regmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
247 views26 pages

INT 220 MCQs

The document provides links to multiple choice questions (MCQs) and tests related to PHP basics, variables, control structures, and loops. It includes sample questions and answers on PHP fundamentals like print vs echo, variable scoping and operators, if/else and switch statements, and while/do-while loops.

Uploaded by

Biraj Regmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

MCQ  https://letsfindcourse.

com/technical-questions/php-questions-answers/print-echo-in-php-
mcqs

MCQ https://letsfindcourse.com/technical-questions/php-questions-answers/print-echo-mcq-php

MCQ https://www.sanfoundry.com/php-coding-questions-answers-print/

MCQ https://www.cppbuzz.com/php/php-objective-questions

MCQ  https://compsciedu.com/mcq-questions/PHP/Constants-and-Operators-in-PHP/6

Test  https://letsfindcourse.com/technical-questions/php-questions-answers/variables-in-php-
mcq

Test  https://www.examveda.com/mcq-question-on-php/

Test  http://www.allindiaexams.in/engineering/cse/php-questions-and-answers/php-variables

Test  https://www.sanfoundry.com/php-coding-questions-answers-variables-1/

While  https://letsfindcourse.com/technical-questions/php-questions-answers/php-loop-mcq

Array  https://letsfindcourse.com/technical-questions/php-questions-answers/php-array-mcq

Array  http://www.allindiaexams.in/engineering/cse/php-questions-and-answers/php-arrays

Array https://www.atnyla.com/general-knowledge/91/214

Basics:
Which of the following is not a prepackaged server stack?

a) WAMP

b) XAMPP

c) MAMP

d) NAMP

Ans. D

Is PHP?

a. interpreted

b. compiled
c. both

Ans. C

What will be the output of the following PHP code?

<?php

echo "Hello world </br> I am learning PHP";

?>

A. Hello world

B. Hello world I am learning PHP

C. Hello world

I am learning PHP

D. Error

Ans. C

What will be the output of the following PHP code ?

<?php

echo "Hello world <strong>I am learning PHP</strong>"

?>

a. Hello world

b. Hello world I am learning PHP

c. Hello world

I am learning PHP

d. Error

Ans. b

What will be the output of the following PHP code?

<?php
echo "I"."am"."learning"."php";

?>

A. Iamlearningphp

B. I am learning php

C. Nothing

D. error

Ans. A

What will be the output of the following PHP code?

<?php

echo "I","am","learning","php";

?>

A. Iamlearningphp

B. I am learning php

C. Nothing

D. error

Ans. A

which of the following is correct echo statement?

A. echo "<h2>PHP is Fun!</h2>";

B. echo "PHP is Fun!<br>";

C. echo "PHP ", "is ", "Fun!";

D. All of the above

Ans. D

What will be the output of the following PHP code?

<?php
echo "This is "echo statement" ";

?>

A. This is "echo statement"

B. echo statement

C. Error

D. No Output

Ans. C

What will be output of the following code?

<?php

<input type=text>

?>

a. A text box will be displayed


b. Error
c. Nothing will be displayed
d. None

Ans. b

What will be output of the following code?

<?php echo “<input type=text>”?>

a. A text box will be displayed


b. Error
c. Nothing will be displayed
d. None

Ans. a

Which one the following comment is invalid in PHP?

(A) //echo "Hello";

(B) // /* echo "Hello"; */

(C) /* echo "Hello"; */


(D) /* //echo "Hello"; */

(E) None

Ans. E

which of the following is correct print statement?

A. print "<h2>PHP is Fun!</h2>";

B. print "PHP is Fun!<br>";

C. print "PHP ", "is ", "Fun!";

D. All of the above

Ans. D

What will be the output of the following PHP code?

<?php

print("I"."am"."learning"."php");

?>

A. Iamlearningphp

B. I am learning php

C. Nothing

D. error

Ans. A

What will be the output of the following PHP code?

<?php

print("I","am","learning","php");

?>

A. Iamlearningphp

B. I am learning php
C. I,am,learning,php

D. error

Ans. A

print statement can take _____ argument?

A. 1

B. 2

C. 3

D. 4

Ans. A

How many ways user can print output in PHP?

A. 1

B. 2

C. 3

D. 4

Ans. B

What will be the output of the following PHP code?

<?php

print "echo hello world";

?>

a) echo hello world

b) hello world

c) nothing

d) error

Ans. A
How we closed the php scripts

a. <php. . . .>

b. <?php. . . >

c. <?php . . . ?>

d. <p. . . p>

Ans. B

Variables:
What will be the output of the following PHP code ?

<?php

$one = "Hello";

$two = "World";

echo $one, $two;

?>

a. Hello World

b. Hello

c. World

d. HelloWorld

Ans. d

What will be the output of the following PHP code?

<?php

$five = 5;

print($five);

print $five;

?>
a. 05
b. 55
c. 50
d. Error

Ans. B

Find correct way of declaring variables:

(A) $-a = 10;

(B) $1a = 10;

(C) $1a1 = 10;

(D) $a1 = 10;

Ans. D

What will be the output of the following PHP code ?

<?php

define("GREETING", "PHP is a scripting language", true);

echo GREETING;

echo "<br>";

echo "GREETING";

?>

a. PHP is a scripting language


GREETING
b. GREETING
GREETING

c. GREETING

d. PHP is a scripting language

PHP is a scripting language

Ans. a

What will be the output of the following PHP code ?


<?php

define('IF', 42);

echo "IF: ", IF;

?>

a. IF:42

b. No output

c. IF:

d. ERROR

Ans. d

What will be the output of the following PHP code ?

<?php

define("NEW_GOOD_NAME_CONSTANT", "I have a value");

define("OLD_BAD_NAME_CONSTANT", NEW_GOOD_NAME_CONSTANT);

echo NEW_GOOD_NAME_CONSTANT;

echo OLD_BAD_NAME_CONSTANT;

?>

a. I have a value

b. I have a valueI have a value

c. ERROR

d. I have a valueNEW_GOO_NAME_CONSTANT

Ans. a

What will be the output of the following PHP code ?

<?php

$one = "Hello";

$two = "World";
echo "$one"+"$two";

?>

a. HelloWorld

b. Hello+World

c. 0

d. Error

Ans. c

What will be the output of the following PHP code ?

<?php

$color1 = "red";

$color2 = "1";

$color3 = "grey"

echo "$color1" + "$color2" . "$color3";

?>

A. 1grey

B. grey

C. 0

D. red1grey

Ans. A

What will be the output of the following PHP code ?

<?php

$x = 4;

$y = 3;

$z = 1;

echo "$x = $x + $y + $z";


?>

A. 4 = 4 + 3 + 1

B. 8

C. 8 = 4 + 3 +1

D. Error

Ans. A

What will be the output of the following PHP code ?

<?php

$y = 2;

$w = 4;

$y *= $w /= $y;

echo $y, $w;

?>

a. 80.5
b. 44
c. 82
d. 42

Ans. d

What will be the output of the following PHP code ?

<?php

$x = "test";

$y = "this";

$z = "also";

$x .= $y .= $z ;

echo $x;

echo $y;

?>
a. testthisthisalso

b. testthis

c. testthisalsothisalso

d. error at line 4

Ans. c

What will be the output of the following PHP code ?

<?php

$a = 10;

echo ++$a;

echo $a++;

echo $a;

echo ++$a;

?>

a. 11111213
b. 11121213
c. 11111212
d. 11111112

Ans. a

What will be the output of the following PHP code ?

<?php

$one = "one";

$two = "two";

print($one==$two);

?>

A. true

B. false

C. nothing
D. error

Ans. C

Control Structures:
What will be the output of the following PHP code ?

<?php

$y = 2;

if ($y-- == ++$y)

echo $y;

?>

a. 2
b. 1
c. 3
d. no output

Ans. a

What will be the output of the following PHP code ?

<?php

$y = 2;

if (**$y == 4)

echo $y;

?>

a. 4
b. 2
c. error at line2
d. no output

Ans. c

What will be the output of the following PHP code ?

<?php

$y = 2;

if (--$y == 2 || $y xor --$y)

echo $y;

?>

a. 1
b. 0
c. 2
d. no output

Ans. b

What will be the output of the following PHP code ?

<?php

$auth = 1;

$status = 1;

if ($result = (($auth == 1) && ($status != 0)))

print "result is $result<br />";

?>

a. result is true
b. result is 1
c. error
d. no output

Ans. b

What will be the output of the following PHP code?

<?php

$a = "1";

switch ($a)

case 1:

print "hi";

case 2:

print "hello";

default:

print "hi1";

?>

a) hihellohi1

b) hi

c) hihi1

d) hi1

Ans. a

What will be the output of the following PHP code?

<?php

$a = "2";

switch ($a)

{
case 1:

print "hi";

case 2:

print "hello";

break;

default:

print "hi1";

?>

a) hihellohi1

b) hello

c) hihi1

d) hi1

Ans. b

What will be the output of the following PHP code?

<?php

$a = "1";

switch($a)

case 1:

break;

print "hi";

case 2:

print "hello";

break;

default:
print "hi1";

?>

a) hihellohi1

b) no output

c) hihi1

d) hi1

Ans.b

What will be the output of the following PHP code ?

<?php

$a = "1";

$a = 1;

$b = 1;

switch($a)

case $a * $b:

print "hi";

break;

case $a / $b:

print "hello";

break;

default:

print "hi1";

?>

a. hihellohi1
b. hi

c. hihello

d. hi1

Ans. b

What will be the output of the following PHP code ?

<?php

$b = 1;

switch($b)

case 1.0:

print "hi";

break;

case 1:

print "hello";

break;

default:

print "hi1";

?>

a. hihellohi1

b. hi

c. hihello

d. hello

Ans. b

Loops:
What will be the output of the following PHP code ?
<?php

$i = 0;

while ($i = 10)

print "hi";

print "hello";

?>

a. hello

b. infinite loop

c. hihello

d. error

Ans. b

What will be the output of the following PHP code ?

<?php

$i = 5;

while (--$i > 0)

$i++;

print $i;

print "hello";

?>

a. 4hello4hello4hello4hello4hello…..infinite

b. 5hello5hello5hello5hello5hello…..infinite

c. no output
d. error

Ans. b

What will be the output of the following PHP code?

<?php

$num = 20;

while ($num < 12) {

$num += 2;

echo $num, "\n";

?>

A. Error

B. No Output

C. infinite loop

D. Only one garbage value

Ans. B

What will be the output of the following PHP code ?

<?php

$i = 2;

while (++$i)

while (--$i > 0)

print $i;

?>
a. 210

b. 10

c. no output

d. infinite loop

Ans. d

What will be the output of the following PHP code ?

<?php

while()

print "hi";

?>

A. infinite loop

B. hi

C. no output

D. error

Ans. D

What will be the output of the following PHP code ?

<?php

do

print "hi";

while(0);

print "hello";
?>

A. infinite loop

B. hihello

C. hello

D. error
Ans. B

What will be the output of the following PHP code ?

<?php

$i = 0;

while ($i++)

print $i;

print $i;

?>

A. 0

B. infinite loop

C. 01

D. 1

Ans. D

What will be the output of the following PHP code ?

<?php

$i = "";

while($i)

print "hi";
}

print "hello";

?>

A. hello

B. infinite loop

C. hihello

D. error

Ans. A

What will be the output of the following PHP code ? 

<?php

$i = 0;

while($i = 10)

print "hi";

print "hello";

?>

A. hello

B. infinite loop

C. hihello

D. error

Ans. B

Arrays:
Which of the following are correct ways of creating an array?

i) arr[0] = "webofscience";
ii) $arr[] = array("webofscience");

iii) $arr[0] = "webofscience";

iv) $arr = array("webofscience");

A. ii), iii) and iv)

B. ii) and iii)

C. Only i)

D. iii) and iv)

Ans : D

Explanation: A variable name should start with $ symbol which is not present in i) and you need not
put the square brackets when you use the array(), constructor.

What will be the output of the following PHP code?

<?php

$state = array ("Karnataka", "Goa", "Tamil Nadu",

"Andhra Pradesh");

echo (array_search ("Tamil Nadu", $state) );

?>

a) True

b) 1

c) False

d) 2

Ans. d
There are three different kind of arrays:

A) Numeric array, String array, Multidimensional array

B) Numeric array, Associative array, Dimensional array

C) Numeric array, Associative array, Multidimensional array

D) Const array, Associative array, Multidimensional array

Ans. C

The … function searches on the array for a specified value, returning its key if located and FALSE
otherwise.

A) array_values()

B) array_keys()

C) array_search()

D) array_key_exists()

Ans. D

Example:

<?php

$a=array("Volvo"=>"XC90","BMW"=>"X5");

if (array_key_exists("Volvo",$a))

echo "Key exists!";

else

echo "Key does not exist!";

?>
What will be the output of the following PHP code?

< ?php

$fruits = array ("mango", "apple", "pear", "peach");

$fruits = array_flip($fruits);

echo ($fruits[0]);

?>

a. mango
b. Error
c. Peach
d. 0

Ans. b

What will be the output of the following PHP code?

< ?php

$number = array ("4", "hello", 2);

echo (array_sum ($number));

?>

a. 4hello2
b. 4
c. 2
d. 6

Ans. D

You might also like