1. What will be the output of the following PHP code ?
1.<?php
2.echo “Hello world </br> I am learning PHP”;
3.?>
a) Hello world
b) Hello world I am learning PHP
c) Hello world
I am learning PHP
d) Error
2. What will be the output of the following PHP code ?
1.<?php
2.echo “Hello world <strong>I am learning PHP</strong>”
3.?>
a) Hello world
b) Hello world I am learning PHP
c) Hello world
I am learning PHP
d) Error
3. What will be the output of the following PHP code ?
1.<?php
2.echo “This”, “was”, “a”, “bad”, “idea”;
3.?>
a) This, was, a, bad, idea
b) This was a bad idea
c) Thiswasabadidea
d) Error
4. What will be the output of the following PHP code ?
1.<?php
2.echo “This”.”was”.”a”.”bad”.”idea”;
3.?>
a) This, was, a, bad, idea
b) This was a bad idea
c) Thiswasabadidea
d) Error
5. What will be the output of the following PHP code ?
1.<?php
2.echo “This”,”was”|”a”,”bad”.”idea”;
3.?>
a) Thiswasabadidea
b) Thiswasbadidea
c) Thiswas a badidea
d) Thiswas abadidea
6. What will be the output of the following PHP code ?
1.<?php
2.$one = “Hello”;
3.$two = “World”;
4.echo $one, $two;
5.?>
a) Hello World
b) Hello
c) World
d) HelloWorld
7. What will be the output of the following PHP code ?
1.<?php
2.$one = “Hello”;
3.$two = “World”;
4.echo “$one$two”;
5.?>
a) HelloWorld
b) $one$two
c) Hello
d) Error
8. What will be the output of the following PHP code ?
1.<?php
2.$one = “Hello”;
3.$two = “World”;
4.echo “$one”+”$two”;
5.?>
a) HelloWorld
b) Hello+World
c) 0
d) Error
9. What will be the output of the following PHP code ?
1.<?php
2.echo “This is <i>India</i>”;
3.?>
a) This is India
b) This is India
c) This is
d) Error
10. What will be the output of the following PHP code ?
1.<?php
2.$cars = array(“Volvo”, “BMW”, “Toyota”);
3.echo “My car is a {$cars[0]}”;
4.?>
a) My car is a Volvo
b) My car is a BMW
c) My car is a Toyota
d) Error
11. 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
12. What will be the output of the following PHP code ?
1.<?php
2.$i = “”;
3.while ($i = 10)
4.{
5. print “hi”;
6.}
7.print “hello”;
8.?>
a) hello
b) infinite loop
c) hihello
d) error
13. 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
14. 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
15. 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) 54321111111….infinitely
b) 555555555…infinitely
c) 54321
d) 5
16. 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
17. 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
.
18. 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
19. 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
20. 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
21. What will be the output of the following PHP code?
1.<?php
2.$cars = array(“Volvo”, “BMW”, “Toyota”);
3.echo “I like ” . $cars[0] . “, ” . $cars[1] . ” and ” . $cars[2] . “.”;
4.?>
a) I like Volvo BMW and Toyota)
b) I like Volvo, BMW and Toyota)
c) I like Volvo, BMW and Toyota
d) I like. Volvo.,. BMW. and) Toyota) .
22. What will be the output of the following PHP code?
1.<?php
2.$age = array(“Peter”=>”35”, “Ben”=>”37”, “Joe”=>”43”);
3.print_r(array_change_key_case($age, CASE_UPPER));
4.?>
a) Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
b) Array ( [peter] => 35 [ben] => 37 [joe] => 43 )
c) Array ( [PETER] => 35 [BEN] => 37 [JOE] => 43 )
d) Array ( [PeTeR] => 35 [BeN] => 37 [Joe] => 43 )
23. What will be the output of the following PHP code?
1.<?php
2.$cars = array(“Volvo”, “BMW”, “Toyota”, “Honda”, “Mercedes”, “Opel”);
3.print_r(array_chunk($cars, 2));
4.?>
a) Array ( [0] => Array ( [1] => Volvo [2] => BMW ) [1] => Array ( [1] => Toyota [2] => Honda ) [2] => Array ( [1] => Mercedes [2] => Opel ) )
b) Array ( [1] => Array ( [1] => Volvo [2] => BMW ) [2] => Array ( [1] => Toyota [2] => Honda ) [3] => Array ( [1] => Mercedes [2] => Opel ) )
c) Array ( [0] => Array ( [0] => Volvo [1] => Volvo ) [1] => Array ( [0] => BMW [1] => BMW ) [2] => Array ( [0] => Toyota [1] => Toyota ) )
d) Array ( [0] => Array ( [0] => Volvo [1] => BMW ) [1] => Array ( [0] => Toyota [1] => Honda ) [2] => Array ( [0] => Mercedes [1] => Opel ) )
24. What will be the output of the following PHP code?
1.<?php
2.$fname = array(“Peter”, “Ben”, “Joe”);
3.$age = array(“35”, “37”, “43”);
4.$c = array_combine($fname, $age);
5.print_r($c);
6.?>
a) Array ( Peter Ben Joe )
b) Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
c) Array ( 35 37 43 )
d) Array ( “[Peter] => 35″ “[Ben] => 37″ “[Joe] => 43″ )
25. What will be the output of the following PHP code?
1.<?php
2.$a = array(“A”, “Cat”, “Dog”, “A”, “Dog”);
3.print_r(array_count_values($a));
4.?>
a) Array ( [A] => 2 [Cat] => 1 [Dog] => 2 )
b) Array ( [A] => 2 [Cat] => 2 [Dog] => 1 )
c) Array ( [A] => 1 [Cat] => 1 [Dog] => 2 )
d) Array ( [A] => 2 [Cat] => 1 [Dog] => 1)
26. What will be the output of the following PHP code?
1.<?php
2.$a1 = array(“a”=>”red”, “b”=>”green”, “c”=>”blue”, “d”=>”yellow”);
3.$a2 = array(“e”=>”red”, “f”=>”green”, “g”=>”blue”);
4.$result = array_diff($a1, $a2);
5.print_r($result);
6.?>
a) Array ( [d] => yellow )
b) Array ( [c] => blue )
c) Array ( [a] => red )
d) Array ( [e] => yellow )
27. What will be the output of the following PHP code?
1.<?php
2.$a1 = array_fill(3, 4, “blue”);
3.$b1 = array_fill(0, 1, “red”);
4.print_r($a1);
5.echo “<br>”;
6.print_r($b1);
7.?>
a) Array ( [3] => blue [4] => blue)
Array ( [0] => red )
b) Array ( [4] => blue [5] => blue [6] => blue)
Array ( [0] => red )
c) Array ( [3] => blue [4] => blue [5] => blue [6] => blue )
Array ()
d) Array ( [3] => blue [4] => blue [5] => blue [6] => blue )
Array ( [0] => red )
28. What will be the output of the following PHP code?
1.<?php
2.$a1 = array(“red”, “green”);
3.$a2 = array(“blue”, “yellow”);
4.print_r(array_merge($a1, $a2));
5.?>
a) Array ( [0] => red [1] => green)
b) Array ( [0] => blue [1] => yellow [2] => red [3] => green )
c) Array ( [0] => red [1] => green [2] => blue [3] => yellow )
d) Array ( [0] => blue [1] => yellow )
.
29. What will be the output of the following PHP code?
1.<?php
2.$a = array(“a”=>”red”, “b”=>”green”, “c”=>”blue”);
3.echo array_shift($a);
4.print_r ($a);
5.?>
a) green
b) red
c) blue
d) none of the above
30. What will be the output of the following PHP code?
1.<?php
2.$a = array(“red”, “green”, “blue”);
3.array_pop($a);
4.print_r($a);
5.?>
a) Array ( [0] => red [1] => green )
b) Array ( [0] => green [1] => blue )
c) Array ( [0] => red [1] => blue )
d) Array ( [0] => blue [1] => blue )
Answers
1-c | 2-b | 3-c | 4-c | 5-b |
6-d | 7-a | 8-c | 9-b | 10-a |
11-b | 12-b | 13-a | 14-b | 15-a |
16-a | 17-c | 18-a | 19-a | 20-d |
21-b | 22-c | 23-d | 24-b | 25-a |
26-a | 27-d | 28-c | 29-b | 30-a |