PHP Set 1 (30 mcqs)

1. What does PHP stand for?
i) Personal Home Page
ii) Hypertext Preprocessor
iii) Pretext Hypertext Processor
iv) Preprocessor Home Page
a) Both i) and iii)
b) Both ii) and iv)
c) Only ii)
d) Both i) and ii)

2. PHP files have a default file extension of..
a) .html
b) .xml
c) .php
d) .ph

3. A PHP script should start with ___ and end with ___:
a) < php >
b) < ? php ?>
c) <? ?>
d) <?php ?>

4. Which of the following is/are a PHP code editor?
i) Notepad
ii) Notepad++
iii) Adobe Dreamweaver
iv) PDT
a) Only iv)
b) All of the mentioned.
c) i), ii) and iii)
d) Only iii)

5. 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)

6. Which version of PHP introduced Try/catch Exception?
a)PHP 4
b)PHP 5
c)PHP 5.3
d)PHP 6

7. 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)

8. 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)

9. 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

10. 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

11. 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 }

12. Type Hinting was introduced in which version of PHP?
a) PHP 4
b) PHP 5
c) PHP 5.3
d) PHP 6

13. 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

14. 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
.
15. 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)

16. 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

17. 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
.
18. 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

19. 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

20. 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

21. PHP’s numerically indexed array begin with position __.
a) 1
b) 2
c) 0
d) -1

22. Which of the following are correct ways of creating an array?
i) state[0] = “karnataka”;
ii) $state[] = array(“karnataka”);
iii) $state[0] = “karnataka”;
iv) $state = array(“karnataka”);
a) iii) and iv)
b) ii) and iii)
c) Only i)
d) ii), iii) and iv)

23. What will be the output of the following php code?
1.<?php
2.$states = array(“karnataka” => array
3.( “population” => “11,35,000”, “captial” => “Bangalore”),
4.”Tamil Nadu” => array( “population” => “17,90,000”,
5.”captial” => “Chennai”) );
6.echo $states[“karnataka”][“population”];
7.?>
a) karnataka 11,35,000
b) 11,35,000
c) population 11,35,000
d) karnataka population

24. Which function will return true if a variable is an array or false if it is not?
a) this_array()
b) is_array()
c) do_array()
d) in_array()

25. Which in-built function will add a value to the end of an array?
a) array_unshift()
b) into_array()
c) inend_array()
d) array_push()

26. What will be the output of the following PHP code?
1.<?php
2.$state = array (“Karnataka”, “Goa”, “Tamil Nadu”,
3.”Andhra Pradesh”);
4.echo (array_search (“Tamil Nadu”, $state) );
5.?>
a) True
b) 1
c) False
d) 2

27. What will be the output of the following PHP code?
1.<?php
2.$fruits = array (“apple”, “orange”, “banana”);
3.echo (next($fruits));
4.echo (next($fruits));
5.?>
a) orangebanana
b) appleorange
c) orangeorange
d) appleapple

28. Which function can be used to move the pointer to the previous array position?
a) last()
b) before()
c) prev()
d) previous()

29. What will be the output of the following PHP code?
1. <?php
2. $fruits = array (“apple”, “orange”, array (“pear”, “mango”),
3.”banana”);
4. echo (count($fruits, 1));
5. ?>
a)3
b)4
c)5
d)6

30. Which function returns an array consisting of associative key/value pairs?
a) count()
b) array_count()
c) array_count_values()
d) count_values()

Answers

1- a 2- c 3- c or d 4- b 5- d
6- b 7- c 8- c 9- b 10- a
11- d 12- b 13- a 14- c 15- a
16- d 17- c 18- c 19- a 20- d
21- c 22- a 23- b 24- b 25- d
26- d 27- a 28- c 29- d 30- c
Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *