0% found this document useful (0 votes)
50 views

PHP MCQ

The document contains a collection of multiple choice questions about PHP. It tests knowledge of PHP fundamentals including what PHP stands for, who created it, common syntax features, and functions. The questions cover topics like arrays, loops, variables, and PHP basics.

Uploaded by

cekexog892
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

PHP MCQ

The document contains a collection of multiple choice questions about PHP. It tests knowledge of PHP fundamentals including what PHP stands for, who created it, common syntax features, and functions. The questions cover topics like arrays, loops, variables, and PHP basics.

Uploaded by

cekexog892
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

PHP MCQ

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 (ii)
B. Both (ii) and (iv)
C. Only (ii)
D. Both (i) and (iii)
Ans.A

2. Who is the father of PHP?


A. Rasmus Lerdorf
B. Willam Makepiece
C. Drek Kolkevi
D. List Barely
Ans.A

3. PHP files have a default file extension of.


A. .html
B. .xml
C. .php
D. .ph
Ans.C

4. A PHP script should start with ___ and end with ___:

 A.

 < php >

 B.

 < ? php ?>

 C.
 <??>

 D.

< ?php ? >

Ans.D

5. 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
Ans.C

6. 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)
Ans.B

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

9. 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)
Ans.C

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


A. \r
B. \n
C. /n
D. /r
Ans.B

11. 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)
Ans.C

12. What will be the output of the following php code

< ?php

$num = 1;
$num1 = 2;

print $num . "+". $num1 ;

?>

A. 3
B. 1+2
C. 1.+.2
D. Error
Ans.B

13. What will be the output of the following php code?

< ?php

$num = "1";

$num1 = "2";

print $num+$num1 ;

?>

A. 3
B. 1+2
C. Error
D. 12
Ans.A

14. 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)
Ans.D

15. What will be the output of the following code?


< ?php

$foo = 'Bob';

$bar = &$foo;

$bar = "My name is $bar";

echo $bar;

echo $foo;

?>

A. Error
B. My name is BobBob
C. My name is BobMy name is Bob
D. My name is Bob Bob
C

16. PHP’s numerically indexed array begin with position __.


A. 1
B. 2
C. 0
D. -1

Ans.C

17. Which of the functions is used to sort an array in descending order?


A. sort()
B. asort()
C. rsort()
D. dsort()

Ans.C

18. 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)
Ans.A
19. What will be the output of the following PHP code?

< ?php

$fruits = array ("mango", "apple", "pear", "peach");

$fruits = array_flip($fruits);

echo ($fruits[0]);

?>

A. mango
B. Error
C. peach
D. 0
Ans.B

20. What will be the output of the following php code?

< ?php

$states = array("karnataka" => array

( "population" => "11,35,000", "captial" => "Bangalore"),

"Tamil Nadu" => array( "population" => "17,90,000",

"captial" => "Chennai") );

echo $states["karnataka"]["population"];

?>

A. karnataka 11,35,000
B. 11,35,000
C. population 11,35,000
D. karnataka population
Ans.B

21. Which function can be used to move the pointer to the previous array
position?
A. last()
B. before()
C. prev()
D. previous()
Ans.C

22. PHP is _____________ scripting Language?

A. Server side B. Client side

C. Middle side D. None of above

Ans. A

23. PHP script is executed on?

A. ISP Computer B. Server computer

C. Client computer D. None of above

Ans. B

Which of the following variables is not a predefined variable?


A.$get B.$ask

C.$request D.$post

Ans. B

24) When you need to obtain the ASCII value of a character


which of the following function you apply in PHP?
A.chr( ); B.asc( );

C.ord( ); D.val( );

Ans. C
25) Which of the following method sends input to a script via a
URL?
A.Get B.Post

C.Both D.None

Answer : Option A

26) Which of the following function returns a text in title case


from a variable?
A.ucwords($var) B.upper($var)

C.toupper($var) D.ucword($var)

Answer : Option A

27) Which of the following function returns the number of


characters in a string variable?
A.count($variable) B.len($variable)

C.strcount($variable) D.strlen($variable)

Answer : Option D

28) Which of the following are not considered as Boolean false?


a. FALSE b. 0
c. “0” d. “FALSE”
e. 1 f. NULL
Ans: d and e

29) What is the output of the following code?


a. Array ([x]=>9 [y]=>3 [z]=>-7)
b. Array ([x]=>3 [y]=>2 [z]=>5)
c. Array ([x]=>12 [y]=>5 [z]=>-2)
d. Error
e. None of the above
Ans: c
30) Which of the following multithreaded servers allow PHP as a plug-in?
a. Netscape FastTrack
b. Microsoft’s Internet Information Server
c. O’Reilly’s WebSite Pro
d. All of the above
Ans: d

31) Which of the following type cast is not correct?


a. real
b. double
c. decimal
d. boolean
Ans: c

32) which of the following are the valid PHP data types?
a. resource
b. null
c. boolean
d). All of the above
Ans: d

33) which of the following characters are taken care of by htmlspecialchars?


a. < b. >
c. single quote
d. double quote
e. &
f. All of the above
Ans: f

34) which of the following is a correct declaration?


a. static $varb = array(1,’val’,3);
b. static $varb = 1+(2*90);
c. static $varb = sqrt(81);
d. static $varb = new Object;
Ans: a

35) Which of the following is Ternary Operator?


a. &
b. =
c. ?:
e. +=
Ans: c
36) which of the following pair have non-associative equal precedence?
a. +,-
b. ==, !=
c.+, /
d. &=, |=
Ans: b

37) Which of the following functions output text?


a. echo()
b. print()
c. both a,b
d. display()
Ans: c

38) Which of the following statement is not correct for PHP?


a. It is a server side scripting language
b. A PHP file may contain text, html tags or scripts
c. It can run on windows and Linux systems only
d. It is compatible with most of the common servers used today
Ans: c

39) Which of the following printing construct/function accepts multiple


parameters?
a. echo
b. print
c. printf
d. All of the above
Ans: a

40) What will be the output of the following code?


$a = 10;
if ($a > 5 OR < 15)
echo ‘true’;
else
echo ‘false’;
a. true
b. false
c. No output
d. Parse Error
Ans: d
41) Which of the following variable names are invalid?
a. $var_1
b. $var1
c. $var-1
d. $var/1
e. Both c,d
Ans: e

42) What will be the output of following code?


$a = 10;
echo ‘Value of a = $a’;
a. Value of a = 10
b. Value of a = $a
c. Undefined
d. Syntax Error
Ans: a

43) What will be the output of the following code?


$Rent = 250;
function Expenses($Other)
{
$Rent = 250 + $Other;
return $Rent;
}
Expenses(50);
echo $Rent;
a. 300
b. 250
c. 200
d. Program will not compile
Ans: b

45) The following php variables are declared:


$company = ‘ABS Ltd’;
$$company = ‘,Sydney’;
Which of the following is not a correct way of printing ‘ABS Ltd,Sydney’?
a. echo ‘$company $$company’;
b. echo ‘$company ${$company}’;
c. echo ‘$company ${‘ABS Ltd’}’;
d. echo ‘$company {$$company}’;
Ans: a
46) Which of the following is not supported in PHP5?
a. Type Hinting
b. Reflection
c. Magic Methods
d. Multiple Inheritance

Ans: d

47) Which of the following is correct with regard to echo and print?
a. echo is a construct and print is a function
b. echo is a function and print is a construct
c. Both are functions
d. Both are constructs
Ans: d

48) What will be the output of following code?


$a = 10;
echo ‘Value of a = $a’;
a. Value of a = 10
b. Value of a = $a
c. Undefined
d. Syntax Error
Ans: a

49) Which of the following is a PHP resource?


a. Domxml document
b. Odbc link
c. File
d. All of the above
Ans: d

50) In multidimensional arrays rather than a single key they values are stored in

A. Sequence of key values


B. 2 keys
C. linear style
D. None of them

Ans.A

51) PHP arrays are also called as

A. Vector arrays
B. Perl arrays
C. Hashes
D. All of them

Ans.C

52) In vector arrays they elements must have

A. Same size
B. Same type
C. Different size
D. Different type

Ans.B

53) As compared to associative arrays vector arrays are much

A. Faster
B. Slower
C. Stable
D. None of them

Ans.A

54) Which function returns an array consisting of associative key/value pairs?


a) count()
b) array_count()
c) array_count_values()
d) count_values()

Ans.C

55) The updated MySQL extension released with PHP 5 is typically referred to
as..
a) MySQL
b) mysql
c) mysqli
d) mysqly

Ans. C

55) Which one of the following statements is used to create a table?


a) CREATE TABLE table_name (column_name column_type);
b) CREATE table_name (column_type column_name);
c) CREATE table_name (column_name column_type);
d) CREATE TABLE table_name (column_type column_name);

Ans. A

56)Which one of the following statements can be used to select the database?
a) $mysqli=select_db(‘databasename’);
b) mysqli=select_db(‘databasename’);
c) mysqli->select_db(‘databasename’);
d) $mysqli->select_db(‘databasename’);

Ans.D

57) Which of the methods are used to manage result sets using both associative
and indexed arrays?
a) get_array() and get_row()
b) get_array() and get_column()
c) fetch_array() and fetch_row()
d) fetch_array() and fetch_column()

Ans. C

58)Which two predefined variables are used to retrieve information from forms?
a) $GET & $SET
b) $_GET & $_SET
c) $__GET & $__SET
d) GET & SET

Ans. B

59) When you use the $_GET variable to collect data, the data is visible to..
a) none
b) only you
c) everyone
d) selected few

Ans.C

60)When you use the $_POST variable to collect data, the data is visible to..
a) none
b) only you
c) everyone
d) selected fewAns

Ans. B

61)Which function is use to check weather variable is array or not?

A.on_array()

B.is_array()

C.the_array()

D.None

Ans. B

61)Which function add new element at end of array?

A.push()

B.pop()

C.stack()

D.None

Ans. A

62) Which function return last element of array?

A.push()

B.pop()

C.stack()

D.None

Ans. B

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy