1. What will be the output of the following PHP code ?
1.<?php
2.$x = 75;
3.$y = 25;
4.function addition()
5.{
6. $GLOBALS[‘z’] = $GLOBALS[‘x’] + $GLOBALS[‘y’];
7.}
8.addition();
9.echo $z;
10.?>
a) 100
b) error
c) 75
d) 25
2. What will be the output of the following PHP code ?
1.<?php
2.function 2myfunc()
3.{
4. echo “Hello World”;
5.}
6.2myfunc();
7.?>
a) Hello World
b) No Output
c) ERROR
d) None of the above
3. What will be the output of the following PHP code ?
1.<?php
2.function _func()
3.{
4. echo “Hello World”;
5.}
6._func();
7.?>
a) Hello World
b) No Output
c) ERROR
d) None of the above
4. What will be the output of the following PHP code ?
1.<?php
2.function test($int)
3.{
4. if ($int == 1)
5. echo “This Works”;
6. if ($int == 2)
7. echo “This Too Seems To Work”;
8.}
9.test(1);
10.TEST(2);
11.?>
a) This Works
b) This Too Seems To Work
c) This WorksThis Too Seems To Work
d) ERROR
5. What will be the output of the following PHP code ?
1.<?php
2.function mine($num)
3.{
4. $num = 2 + $num;
5.echo $num;
6.}
7.mine(3);
8.?>
a) 3
b) $num
c) 5
d) None of the above
6. What will be the output of the following PHP code ?
1.<?php
2.function mine($num)
3.{
4. $num = 2 + $num;
5. echo “$num”;
6.}
7.mine(3);
8.?>
a) 3
b) $num
c) 5
d) None of the above
7. What will be the output of the following PHP code ?
1.<?php
2.function one($string)
3.{
4. echo “I am “. $String;
5.}
6.one(“Batman”);
7.?>
a) I
am Batman
b) I am
c) Batman
d) ERROR
8. What will be the output of the following PHP code ?
1.<?php
2. function string($title);
3. {
4. $title = ucwords($title);
5. echo lcfirst($title);
6. }
7. string(“you went full retard”);
8.?>
9.a) You went full retard
10.b) You Went Full Retard
11.c) YOU WENT FULL RETARD
12.d) you Went Full Retard
13.[expand title=”View Answer”] Answer:d
14.Explanation: ucwords() changes all the first letters to capitals. lcfirst() changes first letter of a string to small.
15.[/expand]
16.
17.9. What will be the output of the following PHP code ?
18.<pre lang=”php” line=”1″ cssfile=”hk1_style”>
19.<?php
20. function multi($num)
21. {
22. if ($num == 3)
23. echo “I Wonder”;
24. if ($num == 7)
25. echo “Which One”;
26. if ($num == 8)
27. echo “Is The”;
28. if ($num == 19)
29. echo “Correct Answer”;
30. }
31. $can = stripos(“I love php, I love php too!”,”PHP”);
32. multi($can);
33.?>
a) I Wonder
b) Which One
c) Is The
d) Correct Answer
10. What will be the output of the following PHP code ?
function movie($int)
{
$movies = array(“Fight Club”, “Kill Bill”, “Pulp Fiction”);
echo “You Do Not Talk About “. $movie[$integer];
}
movie(0);
?>
a) You Do Not Talk About Fight Club
b) You Do Not Talk About Kill Bill
c) You Do Not Talk About Pulp Fiction
d) None of the above
11. What will be the output of the following PHP code ?
1.<?php
2.for ($x = 1; $x < 10; $x++)
3. for ($y = 1; $y < 5; $y++)
4. print “Hello”;
5.?>
a) Hello….36 times
b) Hello….45 times
c) Hello….50 times
d) Hello….40 times
12. What will be the output of the following PHP code ?
1.<?php
2.for ($count = 1; $count != 20;$count++)
3.{
4. print $count;
5. $count++;
6.}
7.?>
a) Infinite
b) 123…….20
c) 1357…19
d) 13579…21
13. What will be the output of the following PHP code ?
1.<?php
2.for ($count = 1; $count < 20; $count++);
3. print $count;
4.?>
a) 20
b) 19
c) 12345678910….19
d) 12345678910….1920
.
14. What will be the output of the following PHP code ?
1.<?php
2.for ($count = 0; $count < 3;$count++);
3.{
4. print “hi”;continue;print “hello”;
5.}
6.?>
a) hihihi
b) hihellohihellohihello
c) hellohellohello
d) hi
15. What will be the output of the following PHP code ?
1.<?php
2.for ($count = 0; $count<3;$count++);
3.{
4. print “hi”;break;print “hello”;
5.}
6.?>
a) hihihi
b) hihellohihellohihello
c) hellohellohello
d) hi
16. What will be the output of the following PHP code ?
1.<?php
2.for(++$i; ++$i; ++$i)
3.{
4. print $i;
5. if ($i == 4)
6. break;
7.}
8.?>
a) 24
b) 134
c) 1234
d) 1
17. What will be the output of the following PHP code ?
1.<?php
2.for ($i = 0;$i = -1;$i = 1)
3.{
4. print $i;
5. if ($i != 1)
6.break;
7.}
8.?>
a) 0
b) infinite loop
c) -1
d) 1
18. What will be the output of the following PHP code ?
1.<?php
2.for(;;)
3.{
4. print “10”;
5.}
6.?>
a) 10
b) infinite loop
c) no output
d) error
19. What will be the output of the following PHP code ?
1.<?php
2.for ($i = 0; $i < 3; $i++)
3.{
4. for($j = $i; $j > 0; $j–)
5. print ” “;
6. for($k = $j; $k < 3; $k++)
7. print “*”;
8.print “\n”;
9.}
10.?>
a)
*
**
***
b) ***
**
*
c) *
**
***
d) error
.
20. What will be the output of the following PHP code ?
1.<?php
2.for ($i = 0; -5 ; $i++)
3.{
4. print”i”;
5. if ($i == 3)
6. break;
7.}
8.?>
a) 0 1 2 3 4
b) 0 1 2 3
c) 0 1 2 3 4 5
d) error
.
21. What will be the output of the following PHP code ?
1.<?php
2.$x = 10;
3.$y = 5;
4.$z = 3;
5.if ($x / $y / $z)
6. print “hi”;
7.else
8. print “hello”;
9.?>
a) hi
b) hello
c) error
d) no output
22. What will be the output of the following PHP code ?
1.<?php
2.if (!print “hi”)
3. if (print “hello”)
4.print “hi”;
5.?>
a) hi
b) hihellohi
c) hihi
d) no output
.
23. What will be the output of the following PHP code ?
1.<?php
2.if (print “hi” – 1)
3. print “hello”
4.?>
a) hi
b) hihello
c) error
d) no output
.
24. What will be the output of the following PHP code ?
1.<?php
2.$x = 1;
3.if ($x–)
4. print “hi”
5. $x–;
6.else
7. print “hello”
8.?>
a) hi
b) hello
c) error
d) no output
.
25. What will be the output of the following PHP code ?
1.<?php
2.$a = 10;
3.$b = 11;
4.if ($a < ++$a || $b < ++$b)
5. print “hello”;
6.else
7. print “hi”;
8.?>
a) hi
b) hello
c) error
d) no output
26. What will be the output of the following PHP code ?
1.<?php
2.$a = 2;
3.if ($a– – –$a – $a)
4. print “hello”;
5.else
6. print “hi”;
7.?>
a) hi
b) hello
c) error
d) no output
.
27. What will be the output of the following PHP code ?
1.<?php
2.$a = 2;
3.if ($a– – –$a – $a)
4. print “hello”;
5.else
6. print “hi”;
7.?>
a) hi
b) hello
c) error
d) no output
28. What will be the output of the following PHP code ?
1.<?php
2.$a = “hello”;
3.if ($a.length)
4. print $a.length;
5.else
6. print “hi”;
7.?>
a) hellolength
b) 5
c) hi
d) error
29. What will be the output of the following PHP code ?
1.<?php
2.$a = “hello”;
3.if (strlen($a))
4. print strlen($a);
5.else
6. print “hi”;
7.?>
a) hellolength
b) 5
c) hi
d) error
30. What will be the output of the following PHP code ?
1.<?php
2.$a = “1”;
3.$b = “0”;
4.if ((int)$a && $b)
5. print”hi”;
6.else
7. print “hello”;
8.?>
a)hello
b) no output
c) hi
d) error
Answers
1-a | 2-c | 3-a | 4-c | 5-c |
6-b | 7-d | 8-d | 9-b | 10-a |
11-a | 12-a | 13-a | 14-a | 15-d |
16-a | 17-c | 18-b | 19-a | 20-b |
21-a | 22-a | 23-c | 24-c | 25-a |
26-b | 27-b | 28-a | 29-b | 30-a |