Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
39 views

PHP Exercise Best Questions

Uploaded by

menber228
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

PHP Exercise Best Questions

Uploaded by

menber228
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

1. PHP files have a default file extension of..

a) .html b) .xml c) .php d) .ph


2. A PHP script should start with ___ and end with ___:
a) < php > b) < ? php ?> c) <? ?> d) <?php ?>
3. Which of the following must be installed on your computer so as to run PHP script?
i) Adobe Dreamweaver
ii) PHP
iii) Apache
iv) IIS
a) All of the mentioned. b) Only ii) c) ii) and iii) d) ii), iii) and iv)
4. We can use ___ to comment a single line?
i) /?
ii) //
iii) #
iv) /* */
a) Only ii) b) i), iii) and iv) c) ii), iii) and iv) d) Both ii) and iv)
5. Which of the following php statement/statements will store 111 in variable num?
i) int $num = 111;
ii) int mum = 111;
iii) $num = 111;
iv) 111 = $num;
a) Both i) and ii) b) All of the mentioned. c) Only iii) d) Only i)
6. What will be the output of the following php code?
1. <?php
2. $num = 1;
3. $num1 = 2;
4. print $num . "+". $num1;
5. ?>

a) 3 b) 1+2 c) 1.+.2 d) Error


7. What will be the output of the following php code?
1. <?php
2. $num = "1";
3. $num1 = "2";
4. print $num+$num1;
5. ?>

a) 3 b) 1+2 C) Error d) 12
8. Which of following variables can be assigned a value to it?
i) $3hello
ii) $_hello
iii) $this
iv) $This
a) All of the mentioned b) Only ii) c) ii), iii) and iv) d) ii) and iv)
9. What will be the output of the following code?
1. <?php
2. $foo = 'Bob';
3. $bar = &$foo;
4. $bar = "My name is $bar";
5. echo $bar;
6. echo $foo;
7. ?>
a) Error
b) My name is BobBob
c) My name is BobMy name is Bob
d) My name is Bob Bob
10. Which of the following PHP statements will output Hello World on the screen?
i) echo (“Hello World”);
ii) print (“Hello World”);
iii) printf (“Hello World”);
iv) sprintf (“Hello World”);
a) i) and ii) b) i), ii) and iii) c) All of the mentioned d) i), ii) and iv)
11. What will be the output of the following PHP code?
1. <?php
2. $color = "maroon";
3. $var = $color[2];
4. echo "$var";
5. ?>
a) a b) Error c) $var d) r
12. What will be the output of the following PHP code?
1. <?php
2. $score = 1234;
3. $scoreboard = (array) $score;
4. echo $scoreboard[0];
5. ?>
a) 1 b) Error c) 1234 d) 2
13. What will be the output of the following PHP code?
1. <?php
2. $total = "25 students";
3. $more = 10;
4. $total = $total + $more;
5. echo "$total";
6. ?>
a) Error b) 35 students c) 35 d) 25 students
14. Which of the below statements is equivalent to $add += $add ?
a) $add = $add
b) $add = $add +$add
C) $add = $add + 1
d) $add = $add + $add + 1
15. Which statement will output $x on the screen?
a) echo “\$x”; b) echo “$$x”; c) echo “/$x”; d) echo “$x;”;
16. What will be the output of the following code?
1. <?php
2. function track() {
3. static $count = 0;
4. $count++;
5. echo $count;
6. }
7. track();
8. track();
9. track();
10. ?>
a) 123 b) 111 c) 000 d) 011
17. What will be the output of the following PHP code?
1. <?php
2. $a = "clue";
3. $a .= "get";
4. echo "$a";
5. ?>
a) get b) true c) false d) clueget
18. 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
19. 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.
20. 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
21. Which of the looping statements is/are supported by PHP?
i) for loop
ii) while loop
iii) do-while loop
iv) foreach loop
a) i) and ii) b) i), ii) and iii) c) All of the mentioned d) None of the mentioned
22. 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
23. If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?
a) 12 b) 1 c) Error d) 5
24. 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.
25. 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 }
26. 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)
27. 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
28. 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
29. 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
30. What will be the output of the following PHP code ?
1. <?php
2. echo 'Hello World';
3. <html>
4. Hello world
5. </html>
6. ?>
a) Hello world
b) Hello World Hello World
c) Hello world
Hello World
d) Syntax Error
31. What will be the output of the following PHP code ?
1. <?php
2. $color = "red";
3. echo "$color";
4. echo "$COLOR";
5. echo "$Color";
6. ?>
a) redredred b) redred c) red d) Error
32. What will be the output of the following PHP code ?
1. <?php
2. # echo "Hello world";
3. echo "# Hello world";
4. ?>
a) # Hello world
b) Hello world# Hello world
c) Hello world
d) Error
33. What will be the output of the following PHP code ?
1. <?php
2. echo "<i>Hello World</i>"
3. ?>
a) Hello world b) Hello world in italics c) Nothing d) Error
34. What will be the output of the following PHP code ?
1. <?php
2. $color = red;
3. echo "\$color";
4. ?>
a) red b) $color c) \red d) Error
35. What will be the output of the following PHP code ?
1. <?php
2. $color = red;
3. echo "$color" . red ;
4. ?>
a) red red b) red c) Error d) Nothing
36. What will be the output of the following PHP code ?
1. <?php
2. $color1 = red;
3. $color2 = green;
4. echo "$color1"."$color2";
5. ?>
a) red green b) red c) green d) Error
37. What will be the output of the following PHP code ?
1. <?php
2. $color = "red";
3. $color = "green";
4. echo "$color";
5. ?>
a) red b) green c) red green d) error
38. What will be the output of the following PHP code ?
1. <?php
2. $color1 = "red";
3. $color2 = "green";
4. echo "$color1" + "$color2";
5. ?>
a) redgreen b) red green c) 0 d) error
39. What will be the output of the following PHP code ?
1. <?php
2. $color1 = "red";
3. $color2 = "1";
4. echo "$color1" + "$color2";
5. ?>
a) red1 b) red 1 c) 0 d) 1
40. What will be the output of the following PHP code ?
1. <?php
2. $color1 = "1";
3. $color2 = "1";
4. echo "$color1" + "$color2";
5. ?>
a) 11 b) 2 c) 0 d) 1
41. What will be the output of the following PHP code ?
1. <?php
2. $color1 = "red";
3. $color2 = "1";
4. $color3 = "grey"
5. echo "$color1" + "$color2" . "$color3";
6. ?>
a) 1grey b) grey c) 0 d) red1grey
42. What will be the output of the following PHP code ?
1. <?php
2. $x = 5;
3. $y = 10;
4. $z = "$x + $y";
5. echo "$z";
6. ?>
a) 15 b) 10 + 5 c) $z d) $x + $y
43. What will be the output of the following PHP code ?
1. <?php
2. $x = 4;
3. $y = 3;
4. $z = 1;
5. echo "$x = $x + $y + $z";
6. ?>
a) 4 = 4 + 3 + 1
b) 8
c) 8 = 4 + 3 +1
d) Error
44. What will be the output of the following PHP code ?
1. <?php
2. $x = 4;
3. $y = 3
4. $z = 1;
5. $z = $z + $x + $y;
6. echo "$z";
7. ?>
a) $z b) 15 c) 8 d) 1
45. What will be the output of the following PHP code ?
1. <?php
2. $x = 3.3;
3. $y = 2;
4. echo $x % $y;
5. ?>
a) 0 b) 1 c) 2 d) Error
46. What will be the output of the following PHP code ?
1. <?php
2. $x = 10;
3. $y = 4;
4. $z = 3;
5. echo $x % $y % $z;
6. ?>
a) 0 b) 1 c) 2 d) Error
47. What will be the output of the following PHP code ?
1. <?php
2. $x = 10;
3. $y = 4;
4. $z = 3;
5. echo ($x % ($y) + $z);
6. ?>
a) 5 b) 3 c) 0 d) 1
48. What will be the output of the following PHP code ?
1. <?php
2. $x = 30;
3. $y = 20;
4. $z = 10;
5. echo $x + $y - $z / ($z - $y);
6. ?>
a) 41 b) -4 c) -5 d) 51
49. What will be the output of the following PHP code ?
1. <?php
2. $x = -1;
3. $y = 1;
4. $z = $x * $y + $z;
5. echo $z;
6. ?>
a) Undefined variable z
b) -1
c) Undefined variable z
-1
d) None of the above
50. What will be the output of the following PHP code ?
1. <?php
2. $x = 4;
3. $y = -3;
4. $z = 11;
5. echo 4 + $y * $z / $x;
6. ?>
a) 4.25 b) 3.25 c) -3.25 d) -4.25
51. What will be the output of the following PHP code?
1. <?php
2. $x = 3.5;
3. $y = 2;
4. $z = 2;
5. echo $x / $y / $z;
6. ?>
a) 1.75 b) 0.875 c) 3.5 d) Error
52. What will be the output of the following PHP code ?
1. <?php
2. $on$e = 1;
3. $tw$o = 2;
4. $thre$e = 3;
5. $fou$r = 4;
6. echo "$on$e / $tw$o + $thre$e / $fou$r";
7. ?>
a) 0.75 b) 0.05 c) 1.25 d) Error
53. What will be the output of the following PHP code ?
1. <?php
2. $hello = "Hello World";
3. $bye = "Bye";
4. echo $hello;"$bye";
5. ?>
a) Hello World b) Bye c) Hello worldBye d) Error
54. What will be the output of the following PHP code ?
1. <?php
2. $a = "$winner";
3. $b = "/$looser";
4. echo $a,$b;
5. ?>
a) $winner/$looser b) /$looser c) / d) $looser
55. What will be the output of the following PHP code ?
1. <?php
2. $a = "$winner";
3. $b = "\$looser";
4. echo $a, $b;
5. ?>
a) $winner\$looser b) \$looser c) \ d) $looser
56. What will be the output of the following PHP code ?
1. <?php
2. $x = 5;
3. $y = 10;
4. function fun()
5. {
6. $GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];
7. }
8. fun();
9. echo $y;
10. ?>
a) 5 b) 10 c) 15 d) Error
57. What will be the output of the following PHP code ?
1. <?php
2. function fun()
3. {
4. $x = 0;
5. echo $x;
6. $x++;
7. }
8. fun();
9. fun();
10. fun();
11. ?>
a) 012 b) 123 c) 000 d) 111
58. What will be the output of the following PHP code ?
1. <?php
2. function fun()
3. {
4. static $x = 0;
5. echo $x;
6. $x++;
7. }
8. fun();
9. fun();
10. fun();
11. ?>
a) 012 b) 123 c) 111 d) Error
59. What will be the output of the following PHP code ?
1. <?php
2. static $x = 0;
3. function fun()
4. {
5. echo $x;
6. $x++;
7. }
8. fun();
9. fun();
10. fun();
11. ?>
a) 012 b) 123 c) Nothing d) Error
60. What will be the output of the following PHP code ?
1. <?php
2. $x = 0;
3. function fun()
4. {
5. echo $GLOBALS['x'];
6. $x++;
7. }
8. fun();
9. fun();
10. fun();
11. ?>
a) 000 b) 012 c) Nothing d) Erro
61. What will be the output of the following PHP code ?
1. <?php
2. $a = 10;
3. echo ++$a;
4. echo $a++;
5. echo $a;
6. echo ++$a;
7. ?>
a) 11111213 b) 11121213 c) 11111212 d) 11111112
62. What will be the output of the following PHP code ?
1. <?php
2. $a = 12;
3. --$a;
4. echo $a++;
5. ?>
a) 11 b) 12 c) 10 d) error
63. What will be the output of the following PHP code ?
1. <?php
2. $x = "test";
3. $y = "this";
4. $z = "also";
5. $x .= $y .= $z ;
6. echo $x;
7. echo $y;
8. ?>
a) testthisthisalso
b) testthis
c) testthisalsothisalso
d) error at line 4
64. What will be the output of the following PHP code ?
1. <?php
2. $x = 1;
3. $y = 2;
4. if (++$x == $y++)
5. {
6. echo "true ", $y, $x;
7. }
8. ?>
a) no output b) true 23 c) true 22 d) true 33
65. What will be the output of the following PHP code ?
1. <?php
2. $y = 2;
3. $w = 4;
4. $y *= $w /= $y;
5. echo $y, $w;
6. ?>
a) 80.5 b) 44 c) 82 d) 42
66. What will be the output of the following PHP code ?
1. <?php
2. $y = 2;
3. if ($y-- == ++$y)
4. {
5. echo $y;
6. }
7. ?>
a) 2 b) 1 c) 3 d) no output
67. What will be the output of the following PHP code ?
1. <?php
2. $y = 2;
3. if (**$y == 4)
4. {
5. echo $y;
6. }
7. ?>
a) 4 b) 2 c) error at line2 d) no output
68. What will be the output of the following PHP code ?
1. <?php
2. $y = 2;
3. if (--$y <> ($y != $y++))
4. {
5. echo $y;
6. }
7. ?>
a) 1 b) 0 c) 2 d) no output
69. What will be the output of the following PHP code ?
1. <?php
2. echo $x-- != ++$x;
3. ?>
a) 1 b) 0 c) error d) no output
70. What will be the output of the following PHP code ?
1. <?php
2. $i = 0;
3. while ($i = 10)
4. {
5. print "hi";
6. }
7. print "hello";
8. ?>
a) hello b) infinite loop c) hihello d) error
71. What will be the output of the following PHP code ?
1. <?php
2. $i = 5;
3. while (--$i > 0)
4. {
5. $i++;
6. print $i;
7. print "hello";
8. }
9. ?>
a) 4hello4hello4hello4hello4hello…..infinite
b) 5hello5hello5hello5hello5hello…..infinite
c) no output
d) error
72. What will be the output of the following PHP code ?
1. <?php
2. $i = 5;
3. while (--$i > 0 && ++$i)
4. {
5. print $i;
6. }
7. ?>
a) 5 b) 555555555…infinitely c) 54321 d) error
73. What will be the output of the following PHP code ?
1. <?php
2. $i = 0;
3. while(++$i || --$i)
4. {
5. print $i;
6. }
7. ?>
a) 1234567891011121314….infinitely
b) 01234567891011121314…infinitely
c) 1
d) 0
74. What will be the output of the following PHP code ?
1. <?php
2. $i = 0;
3. while (++$i && --$i)
4. {
5. print $i;
6. }
7. ?>
a) 1234567891011121314….infinitely
b) 01234567891011121314…infinitely
c) no output
d) error
75. What will be the output of the following PHP code ?
1. <?php
2. $i = 0;
3. while ((--$i > ++$i) - 1)
4. {
5. print $i;
6. }
7. ?>
a) 00000000000000000000….infinitely
b) -1-1-1-1-1-1-1-1-1-1…infinitely
c) no output
d) error
76. What will be the output of the following PHP code ?
1. <?php
2. $i = 2;
3. while (++$i)
4. {
5. while ($i --> 0)
6. print $i;
7. }
8. ?>
a) 210
b) 10
c) no output
d) infinite loop
77. What will be the output of the following PHP code ?
1. <?php
2. $i = 2;
3. while (++$i)
4. {
5. while (--$i > 0)
6. print $i;
7. }
8. ?>
a) 210
b) 10
c) no output
d) infinite loop

You might also like