PHP 2

COEP
Lets Crack Online Exam

IT Interview Exam Paper: PHP 2

Subject: PHP 2

Part 2: List for questions and answers of PHP


Q1. What will be the output of the following PHP code?

1.<?php

2.$a = 5;

3.$b = 5;

4.echo ($a === $b);

5.?>

a) 5 === 5

b) Error

c) 1

d) False

 

Q2. Which of the below symbols is a newline character?

a) \r

b) \n

c) /n

d) /r

 

Q3. What will be the output of the following PHP code?

1.<?php

2.$num = 10;

3.echo ‘What is her age? \n She is $num years old’;

4.?>

a) What is her age? \n She is $num years old

b) What is her age? She is $num years old

c) What is her age? She is 10 years old

d) What is her age?

 

Q4. Which of the conditional statements is/are supported by PHP?

i)if statements

ii)if-else statements

iii)if-elseif statements

iv)switch statements

a) Only i)

b) i), ii) and iv)

c) ii), iii) and iv)

d) All of the mentioned 

 

Q5. What will be the output of the following PHP code?

1.<?php

2.$team = “arsenal”;

3.switch ($team) {

4.case “manu”:

5.echo “I love man u”;

6.case “arsenal”:

7.echo “I love arsenal”;

8.case “manc”:

9. echo “I love manc”; }

10.?>

a) I love arsenal

b) Error

c) I love arsenalI love manc

d) I love arsenalI love mancI love manu

 

Q6. Which of the looping statements is/are supported by PHP?

i)for loop

ii)while loop

iii)do-while loop

iv)foreach loop

a) and ii)

b) i), ii) and iii)

c) All of the mentioned

d) None of the mentioned

 

Q7. What will be the output of the following PHP code?

1.<?php

2.$user = array(“Ashley”, “Bale”, “Shrek”, “Blank”);

3.for ($x=0; $x < count($user); $x++) {

4.if ($user[$x] == “Shrek”) continue;

5.printf ($user[$x]);

6.}

7.?>

a) AshleyBale

b) AshleyBaleBlank

c) ShrekBlank

d) Shrek 

 

Q8. If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?

a) 12

b) 1

c) Error

d) 5

 

Q9. What is the value of $a and $b after the function call?

1.<?php

2.function doSomething( &$arg ) {

3.$return = $arg;

4.$arg += 1;

5.return $return;

6.}

7.$a = 3;

8.$b = doSomething( $a );

9.?>

a) a is 3 and b is 4

b) a is 4 and b is 3

c) Both are 3

d) Both are 4

 

Q10. Who is the father of PHP?

a) Rasmus Lerdorf

b) Willam Makepiece

c) Drek Kolkevi

d) List Barely

 

Q11. Which one of the following is the right way of defining a function in PHP?

a) function { function body }

b) data type functionName(parameters) { function body }

c) functionName(parameters) { function body }

d) function fumctionName(parameters) { function body }

 

Q12. Type Hinting was introduced in which version of PHP?

a) PHP 4

b) PHP 5

c) PHP 5.3

d) PHP 6 

 

Q13. What will happen in this function call?

1.<?php

2.function calc($price, $tax)

3.{

4.$total = $price + $tax;

5.}

6.$pricetag = 15;

7.$taxtag = 3;

8.calc($pricetag, $taxtag);

9.?>

a) Call By Value

b) Call By Reference

c) Default Argument Value

d) Type Hinting

 

Q14. What will be the output of the following PHP code?

1.<?php

2.function calc($price, $tax=””)

3.{

4.$total = $price + ($price * $tax);

5.echo “$total”;

6.}

7.calc(42);

8.?>

a) Error

b) 0

c) 42

d) 84

 

Q15. Which of the following are valid function names?

i)function()

ii)€()

iii).function()

iv)$function()

a) Only ii)

b) None of the mentioned

c) All of the mentioned

d) iii) and iv) 

 

Q16. What will be the output of the following PHP code?

1.<?php

2.function a()

3.{

4.function b()

5.{

6.echo ‘I am b’;

7.}

8.echo ‘I am a’;

9.}

10.a();

11.a();

12.?>

a) I am b

b) I am bI am a

c) Error

d) I am a Error

 

Q17. What will be the output of the following PHP code?

1.<?php

2.function a()

3.{

4.function b()

5.{

6. echo ‘I am b’;

7.}

8.echo ‘I am a’;

9.}

10. b();

11.a();

12.?>

a) I am b

b) I am bI am a

c) Error

d) I am a Error 

 

Q18. What will be the output of the following PHP code?

1.<?php

2.$op2 = “blabla”;

3.function foo($op1)

4.{

5.echo $op1;

6.echo $op2;

7.}

8.foo(“hello”);

9.?>

a) helloblabla

b) Error

c) hello

d) helloblablablabla

 

Q19. A function in PHP which starts with __ (double underscore) is know as..

a) Magic Function

b) Inbuilt Function

c) Default Function

d) User Defined Function

 

Q20. What will be the output of the following PHP code?

1.<?php

2.function foo($msg)

3.{

4.echo “$msg”;

5.}

6.$var1 = “foo”;

7.$var1(“will this work”);

8.?>

a) Error

b) $msg

c) 0

d) will this work 

 

Part 2: List for questions and answers of PHP

 

Q1. Answer: c

 

Q2. Answer: b

 

Q3. Answer: a

 

Q4. Answer: d

 

Q5. Answer: c

 

Q6. Answer: d


Q7. Answer: b

 

Q8. Answer: d

 

Q9. Answer: b

 

Q10. Answer: a

 

Q11. Answer: d

 

Q12. Answer: b

 

Q13. Answer: a

 

Q14. Answer: c

 

Q15. Answer: a

 

Q16. Answer: d

 

Q17. Answer: c

 

Q18. Answer: c

 

Q19. Answer: a

 

Q20. Answer: d