PHP MCQs

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Sr No.

MCQs Correct
Answer
UNIT I(PHP Basics)
1. What does PHP stand for currently? B
A. Personal Home Page B. Hypertext Pre-processor
C. Pretext Hypertext Pre-processor D. Pretext Home Page

2. PHP files have default file extension of: D


A. ,html B. .xml
C. .py D. .php

3. Which of the following is not a server-side scripting language? C


A. PHP
B. ASP
C. Java Script
D. Python

4. Following are the advantages of some scripting languages. (i) Code B


remain hidden from the user. (ii) It is browser independent. According
to your opinion, it’s a ________ scripting language.
A. Client-Side
B. Server-Side
C. Both
D. None

5. Which of the following is not a feature of PHP? B


A. Open Source
B. Suitability
C. Flexibility
D. Embedded with HTML

6. We can execute PHP scripts on Windows as well as Linux based D


platform. Which feature state so?
A. Open source
B. Cost
C. Strong user community
D. Cross platform compatibility

7. What should be the correct syntax to write a PHP code? C


A. <php> B. <? ?>
C. <?php ?> D. <?php>

8. Which of the following is/are a PHP code editor? D


A. Adobe Dreamweaver B. Notepad++
C. Sublime Text3 D. All of the above

9. Which of the following must be installed on your computer so as to B


run PHP script?
A. Adobe Dreamweaver B. XAMPP
C. Sublime D. Notepad++

10. PHP Programmer can write the PHP code in which tags? D
A. Canonical Tag <?php //Code ?>
B. Short Tag <? //Code ?>
C. ASP Tag <% Code %>
D. All of the above
11. Which of the following is a composite PHP data-type? C
A. Integer
B. Boolean
C. Array
D. String

12. String within single quote is parsed whereas string within double B
quote is not parsed.
A. True
B. False
C. May be

13. How is single line comment be used in PHP? A


A. // B. /* */
C. /? D. ;

14. Which of the following PHP statement/statements will store 10 in C.


variable num?
A. int $num=10; B. int num=10;
C. $num=10; D. 10=$num;

15. Which PHP built-in function will help you to create constants? C
A. Const()
B. Constant()
C. Define()
D. Include()

16. What will be the output of the following PHP code? B


<?php
$num1 = "1";
$num2 = "2";
print $num1 . "+". $num2;
?>
A. 3 B.1+2
C. Error D. 1 2

17. Which is the correct way of declaring a variable? C


A. $1var B.$var 1
C. $var1 D.All of these
18. Predict the output of the following piece of code. A
$p=90;
$q=90.0;
var_dump($p===$q);

A. bool(false)
B. bool(true)
C. 1
D. 0

19. If we want to preserve the values of local variables that we have B


defined inside the function body for the next function call, we can do
it with the help of __________ keyword.
A. global
B. static
C. function
D. none of these

20. I have declare a variable like; $n = 100; What will be the output of the B
commands echo $n<<2; and echo $n>>2 respectively?
A. 200 50
B. 400 25
C. 50 200
D. 25 400

21. In PHP, the _______ is an error control operator whereas ________ is C


a string concatenation and assignment operator.
A. .= , .
B. ` ` , @
C. @, .=
D. .=, @

22. Which of the following function/functions are used to print message D


and exit from the current php script?
A. Die()
B. Exit()
C. Break()
D. Both exit() and die()

23. What will be the output of the following PHP code? A


<?php
$a= 'Bob';
$b = “a”;
echo $$b;
?>
A. Bob B.a
C. Error D. b

24. Which of the following are correct ways of creating an array? A


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)

25. What will be the output of following code? B


<?php
$states = array("Karnataka" => array ("population" =>
"11,35,000",
"capital" => "Bangalore"), "Tamil Nadu" => array( "population"
=>
"17,90,000", "capital" => "Chennai") );
echo $states["Karnataka"]["population"];
?>
A. Karnataka 11,35,000 B. 11,35,000
C. population 11,35,000 D. Karnataka population

26. Array with alpha-numeric index in PHP is known as _____________ D


A. Indexed Array
B. String Array
C. Access Array
D. Associative Array

27. Which of the below statements is equivalent to $a += $a? D.


A. $a=$a B. $a=$a+$a
C. $a=$a + $a +1 D. $a=$a + 1

28. Which statement will output $x on the screen? A


A. echo “\$x”; B. echo “$$x”;
C. echo “/$x”; D. echo “$x”;

29. What will be the output of following code? C

<?php
function track() {
static $count = 0;
$count++;
echo $count;
}
track();
track();
track();
?>
A. 111 B 000
C. 123 D. 011

30. What will be the output of following code? A


<?php
$a = “5”;
$b = 5;
if($a === $b){
echo “true”;
}
else{
echo “false”;
}
?>
A. false B Error
C. true D. None

31. What will be the output of the following PHP code? C


<?php
$team = "csk";
switch ($team) {
case "mi":
echo "I love Mumbai Indians";
case "csk":
echo "I love Chennai Super Kings";
case "kkr":
echo "I love Kolkata Knight Riders"; }
?>
A. I love Mumbai Indians
B I love Chennai Super Kings
C. I love Chennai Super Kings I love Kolkata Knight Riders
D. I love Kolkata Knight Riders

32. What will be the output of the following PHP code? D


<?php
$user = array("Ashley", "Bale", "Shrek", "Blank");
for ($x=0; $x < count($user); $x++) {
if ($user[$x] == "Shrek") continue;
print ($user[$x]);
}
?>
A. AshleyBale B AshleyBaleShrekBlank
C. AshleyShrekBlank D. AshleyBaleBlank

33. I have defined an array storing marks of the student with its C
associated subject name. I am interested in fetching both key and
value of this array. Which of the following construct should I use?
A. While
B. For
C. Foreach
D. Switch

34. If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed? D


A. 12 B 1
C. Error D. 5

35. I am writing a program to check input number is prime or not. As soon A


as I came to know that a number is divisible indicating a number is not
prime, I want to come out of the loop. Which of the following
statement I have to use?
A. break
B. continue
C. die
D. exit

36. Who is the father of PHP? B.


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

37. What is the full form of WAMP? B


A. Windows Application MySQL and PHP
B. Windows Apache MySQL and PHP
C. Windows Apache MySQL and Perl
D. None of these

38. Variable name in PHP starts with - B


A. ! (Exclamation)
B. $ (Dollar)
C. & (Ampersand)
D. # (Hash)

39. Which of the following is not a variable scope in PHP? A


A. Extern
B. Local
C. Static
D. Global
40. Which of the following is used to display the output in PHP? D
A. echo
B. write
C. print
D. Both echo and print

41. Which of the following is used for concatenation in PHP? B


A. + (plus)
B. . (Asterisk)
C. . (dot)
D. append()

42. Which of the following is true about php.ini file? D


A. The PHP configuration file, php.ini, is the final and most
immediate way to affect PHP's functionality.
B. The php.ini file is read each time PHP is initialized.
C. None of the statement is true
D. Both of the given statement is true

43. What be the will output of following code D

A. Hello World
B. Infinite loop
C. no output
D. Error

44. What will be the output of the code A

A. Hii everyone
B. Hello World
C. Hello World Hii everyone
D. None of the above

45. Predict the output of the following piece of code. C


$g = 40;
Echo “\$g=”.($g>>1);

A. $g=80
B. $g=160
C. $g=20
D. $g=10

46. Which of the following is not true? D


A. PHP can be used to develop web applications.
B. PHP makes a website dynamic
C. PHP applications cannot be compile
D. PHP cannot be embedded into html.

47. PHP is an example of ___________ scripting language. A


A. Server-side
B. Client-side
C. Browser-side
D. In-side

48. Which of the following function displays the information about PHP and B
its configuration?
A. php_info()
B. phpinfo()
C. info()
D. None of the above

49. String values in PHP must be enclosed within - C


A. Double Quotes
B. Single Quotes
C. Both Single and Double Quotes
D. None of the above

50. Which of the following variable name is invalid? C


A. $newVar
B. $new_Var
C. $new-var
D. All of the above

51. Which of the following is the correct way to create an array in PHP? B
A. $season = array["summer" , "winter" , "spring" , "autumn"];
B. $season = array("summer" , "winter" , "spring" , "autumn");
C. $season = "summer" , "winter" , "spring" , "autumn";
D. All of the above
52. Echo returns 1 on success whereas print does not return any value. B
A. True
B. False

53. The ____________ terminates the remaining iteration of the loop A


whereas ____________ statement terminates the current iteration of
the loop.
A. Break, continue
B. For, foreach
C. While, do…while
D. Continue, break

54. I have declare a variable like; $asan=”Chakrasan”; Which of the C


following line will display an output - She is doing Chakrasan?
A. echo ‘She is doing $asan’;
B. echo “She is doing $Asan“;
C. echo “She is doing $asan“;
D. All of these

55. I want to create a constant named COLLEGE with value “MKICS BCA”. C
Which line of code will help me?
A. const(‘COLLEGE’, ‘MKICS BCA’)
B. Constant(‘COLLEGE’, ‘MKICS BCA’)
C. Define(‘COLLEGE’, ‘MKICS BCA’)
D. Include(‘COLLEGE’, ‘MKICS BCA’)
E. None of these

56. I want to compare two values at the same time I am also looking C
forward that the data type of these values must also be same. Which
operator I should use?
A. =
B. ==
C. ===
D. strcasecmp( )

UNIT II(Functions)
57. How to define a function in PHP? D
A. function {function body}
B. type functionName(parameters) {function body}
C. functionName(parameters) {function body}
D. function functionName(parameters) {function body}

58. Does PHP support the concept of conditional function? A


A. Yes
B. No

59. The function in PHP that can be used to concatenate array elements to A
form a single delimited string is –
A. implode()
B. concat()
C. explode()
D. concatenate()

60. Which of the function is used to sort an array in descending order? D


A. asort
B. ksort
C. dsort
D. rsort

61. What will be the output of the following PHP code? C


echo chr(90);
A. a
B. z (lower)
C. Z (upper)
D. Y

62. Which of the following is the use of strpos() function in PHP? C


A. The strpos() function is used to search for the spaces in a string
B. The strpos() function is used to search for a number in a string
C. The strpos() function is used to search for a character/text in a
string
D. The strpos() function is used to search for a capitalize character
in a string

63. Which of the following is the correct use of the strcmp() function in D
PHP?
A. The strcmp() function is used to compare the strings excluding
case
B. The strcmp() function is used to compare the uppercase strings
C. The strcmp() function is used to compare the lowercase strings
D. The strcmp() function is used to compare the strings including
case

64. What is the use of isset() function in PHP? A


A. The isset() function is used to check whether variable is set or
not
B. The isset() function is used to check whether the variable is free
or not
C. The isset() function is used to check whether the variable is
string or not
D. None of the above
65. Pick the odd one out. C
A. current()
B. next()
C. list()
D. prev()

66. Which of the following is not a super global array? D


A. $_POST
B. $_COOKIE
C. $_REQUEST
D. None of these

67. What will be the output of the following code? C


$s="Let your dreams be bigger than your fears";
echo "Position:".strrpos($s,"your");

A. Position:4
B. Position:30
C. Position:31
D. Position:5

68. What will be the output of the following code? D


echo ceil(129.5)."::".floor(129.5)."::".round(129.5);

A. 129::129::129
B. 130::130::130
C. 129::130::129
D. 130::129::130

69. What will be the output of the following PHP code? C


echo "<br>".sqrt(100)."::".pow(10,2);

A. 100::10
B. 100::100
C. 10:100
D. None of the above

70. Which of the following function by default returns the current time B
measured in the number of seconds since January 1 1970 00:00:00?
A. date()
B. time()
C. mktime()
D. curtime()

71. With respect to variable number of arguments in UDF, which of the A


following function returns the number of arguments passed during
function call?
A. func_num_args()
B. func_get_arg()
C. func_get_args()
D. func_get_argv()

72. If you want to check-out that particular element is present in array or B


not. You will use which PHP built-in function?
A. is_array()
B. in_array()
C. present_array()
D. is_found()

73. Which sorting method is used if we want to sort elements of an array D


in ascending order by preserving it key-value association?
A. sort()
B. ksort()
C. arsort()
D. asort()

74. Assume that you have defined one array storing anything and you D
want to access the last element of the array. Which function you will
adopt?
A. current()
B. next()
C. prev()
D. end()

75. Which of the following function(s) can be used to compare two strings C
by ignoring their case?
A. strcmp()
B. compare()
C. strcasecmp()
D. All of these

76. Which of the following function converts a string to all uppercase? D


A. upper()
B. uppercase()
C. struppercase()
D. strtoupper()

77. Which of the following is a built-in function in PHP that adds a value to A
the end of an array?
A. array_push()
B. inend_array()
C. into_array()
D. None of the above

78. Which of the following function(s) is/are used to count total number D
of elements in an array?
A. Count
B. Sizeof
C. Array_count
D. Both count and sizeof

79. I have a number 34.0054 in a variable $x. I want to round up the value B
of this variable irrespective of whether the remaining part is greater
than equal to 5 or not, and store into a variable $y. Which statement
should I write?
A. $y = abs($x);
B. $y = ceil($x)
C. $y = floor($x)
D. $y = round($x)

80. Which of the following date function can be used to make sure a D
particular date is a valid date or not by providing month, day and year
respectively?
A. date()
B. detdate()
C. setdate()
D. checkdate()

81. When we use form method _______, then form data are visible in the A
URL.
A. get
B. post
C. request
D. All of these
E. None of these

82. I want to take an input of joining date of an employee and want to A


assign “doj“ as its name property. I also want to apply a restriction
that user can’t leave this field empty. Suggest me appropriate HTML
code.
A. <input type="date" name="doj" required />
B. <input type="doj" name="date" required />
C. <input type="date" name="doj" />
D. <input type="text" name="doj" required />

83. Assume that you have designed a form having post method. Which D
amongst the following array will store the form data for processing?
A. $_GET
B. $_POST
C. $_REQUEST
D. Both $_POST and $_REQUEST

84. I have designed a form having one submit button and the name D
property of that button is save. Which of the following statement is
correct to check whether save element is present (set) in the
$_REQUEST array or not?
A. if ( present ($_REQUEST[‘save’]) )
B. if (isset $_REQUEST[‘save’] )
C. if ( isset ($_Request[‘save’]) )
D. if ( isset ($_REQUEST[‘save’]) )

85. Which of the following meta character can be used in regular C


expression of the ereg( ) that indicates that there should be zero or
one occurrence of the preceding character or expression?
A. *
B. +
C. ?
D. ^

86. Which of the following function can be used to redirect from one page C
to another page unconditionally?
A. include()
B. location()
C. header()
D. implode()

87. The function in PHP that can be used to concatenate array elements to A
form a single delimited string is -
A. implode()
B. concat()
C. explode()
D. concatenate()
88. We can retrieve the values of query string variables using _________ D
array.
A. Only $_GET
B. Only $_POST
C. Only $_REQUEST
D. Both $_GET and $_REQUEST

89. Which of the following form method of the form element is suggested A
to use when we want to pass sensitive information?
A. POST
B. GET

UNIT III ( Session & Cookies)


90. Which of the following is use to create session? C
A. $_SESSION[]
B. isset() function
C. session_start() function
D. session_destroy() function

91. Which of the following function is used to set cookie in PHP? C


A. createcookie()
B. makecookie()
C. setcookie()
D. None of the above

92. Which of the following function is used to unset a variable in PHP? B


A. delete()
B. unset()
C. unlink()
D. None of the above

93. Which sorting method is used if we want to sort elements of an array B


in descending order of their key at the same time preserving it key-
value association?
A. ksort()
B. krsort()
C. assort()
D. rsort()

94. The ____________ is a persistent user state management technique, A


whereas _______________ is non-persistent user state management
technique.
A. Cookie, Session
B. Session, Cookie
C. Cookie, Query String
D. Query String, Session

95. Which function needs to be called whenever we want to set or get the B
value of session variables?
A. start_session()
B. session_start()
C. mysql_session_start()
D. $_SESSION()

96. Which of the following function is used for both; setting the cookie D
variables as well as to destroy session variables?
A. $_COOKIE[]
B. $_COOKIE()
C. Unset()
D. Setcookie()

97. The _____________ function is used to destroy all session variables. D


A. session_unregister()
B. unset()
C. session_destroys()
D. session_destroy()
98. The _____________ super global array is used to retrieve the B
properties of the file which you have selected using file control.
A. $_FILE
B. $_FILES
C. $_REQUEST
D. $_POST

99. Sapna is a PHP programmer and she has stored the product id ‘P1254’ B
in a variable $pid. She wants to preserve this value for 7 days in a
variable named ck_pid. Which line of code she needs to write in order
to do so?
A. setcookie(“ck_pid”, $pid, 7 * 24 * 60 * 60);
B. setcookie(“ck_pid”, $pid, time() + 7 * 24 * 60 * 60);
C. setcookie(“ck_pid”, $pid,);
D. setcookie(“ck_pid”, $pid, time() - 7 * 24 * 60 * 60);

100. PHP provides the ____________ in-built function to upload file to C


different location other then temporary location.
A. move_upload_file()
B. upload_move_file()
C. move_uploaded_file()
D. uploaded_move_file()
UNIT IV(MySql)
101. Which command is use to remove all the rows from a table? A
A. Truncate
B. Delete
C. Remove
D. Both delete and remove

102. Which Program copies the databases from one server to another B
A. Mysqlflush
B. Mysqldbcopy
C. Mysqlflushdb
D. Mysqlcopydb

103. The ________________ function sends a unique query to the A


currently active database in order to execute it.
A. mysqli_query()
B. mysqli_fetch_array()
C. mysqli_execute()
D. mysqli_select_db()

104. The ____________ storage engine supports FOREIGN KEY referential C


integrity constraints.
A. ISAM
B. MyISAM
C. InnoDB
D. Merge

105. Assume Event table in some database having some records. Which C
SQL command you can use if you want to change the value of
Event_Time field of this table?
A. INSERT
B. ADD
C. UPDATE
D. ALTER

106. Suppose you have designed a database name “db_Quiz”. Which of the D
following line of code is used to select this database in the PHP
application? Assume that connection resource is stored in $con
variable.
A. mysqli_db_select($con, db_Quiz)
B. mysqli_db_select($con, “db_Quiz”)
C. mysqli_select_db($con, db_Quiz)
D. mysqli_select_db($con, “db_Quiz”)
107. While establishing connection of PHP with MySQL using C
mysqli_connect() function, we need to provide name of the MySQL
user. What is the default name of the MySQL user?
A. localhost
B. mysql
C. root
D. mysqli

108. What CSV stands for? C


A. Common Separated Value
B. Command Separated Value
C. Comma Separated Value
D. Comma Standard Value
109. Suppose you want to execute SELECT query that you have stored in a B
variable $q, and the connection is stored in $con resource variable. You
want to store the address of this query’s result in a variable name
$result. Which of the following line you should write to do this job?
A. $res = mysqli_query($con, $q);
B. $result = mysqli_query($con, $q);
C. $result = mysqli_query($q);
D. $result = mysqli_fetch_array($con, $q);

110. Which of the following function will help you, if you want to get the C
number of rows present in the result set of SELECT query?
A. mysqli_fetch_row()
B. mysqli_num_row()
C. mysqli_num_rows()
D. None of these
111. Which of the following function will fetches a result row as an A
associative array, a numeric array, or both.
A. mysqli_fetch_array()
B. mysqli_fetch_row()
C. mysqli_fetch_assoc()
D. mysqli_result()

112. Which of the following function is used to add the content of some D
other file in the current script?
A. Require( )
B. Include( )
C. Include_once( )
D. All of the above

UNIT V(JQuery)
113. Which of the following jQuery method is used to stop jQuery for few B
milliseconds?
A. stop() method
B. delay() method
C. slowdown() method
D. pause() method

114. Which jQuery method is used to set one or more style properties to C
the selected element?
A. The html() method
B. The style() method
C. The css() method
D. All 3 options

115. The jQuery used to find all next sibling elements after the current B
element is –
A. find() method
B. nextAll() method
C. siblings() method
D. None of the above

116. Which of the following jQuery method is used to hide the selected B
elements?
A. The hidden() method
B. The hide() method
C. The visible(false) method
D. The display(none) method

117. Which of the following sign is used as a shortcut for jQuery? C


A. the % sign
B. the & sign
C. the $ sign
D. the @ sign

118. Which tag is used to import the jQuery library file in the code? B
A. <head>
B. <script>
C. <import>
D. <style>

119. Which selector expression will hide all the elements having class cute? B
A. $(.cute).hide();
B. $(“.cute”).hide();
C. $(“#cute”).hide();
D. $(“.cute”).hides();
120. Pick the odd one out. C
A. fadeIn()
B. fadeOut()
C. show()
D. fadeTo()

121. Which of the following jQuery method is used to sets or gets the value D
of form control?
A. html()
B. text()
C. value()
D. val()

122. The ____________ method removes the child elements from the A
selected element whereas the ______________ method removes the
selected element and its child elements.
A. empty() and remove()
B. remove() and empty()
C. delete() and remove()
D. remove() and delete()

123. Which of the following does not belongs to sibling method of a A


jQuery?
A. children()
B. siblings()
C. next()
D. prev()

124. Which of the following is not a jQuery event? B


A. click()
B. onClick()
C. blur()
D. mouseleave()

125. Which of the following selector expression will select the element B
having id “hdng”?
A. $(#hdng)
B. $(‘#hdng’)
C. $(‘.hdng’)
D. $(hdng)

126. Which of the following method does not provides sliding effect? C
A. slideUp()
B. slideDown()
C. fadeIn()
D. slideToggle()

127. I have a dropdown menu in my form having class property “city”. B


What line of jQuery code should I write if I want to get the value of
that menu? Consider that I want to store that value in a variable
named “vcity”.
A. $vcity = $(‘.city’).val();
B. var vcity = $(‘.city’).val();
C. var vcity = $(‘.city’).text();
D. var vcity = $(‘.city’).html();

128. Which of the following jQuery method is used to add as well as C


remove remove one or more CSS class from the selected element?
A. addClass()
B. removeClass()
C. toggleClass()
D. ToggleClass()

129. Which of the following jQuery filtering method returns all elements D
that do not match the criteria?
A. first( )
B. last( )
C. filter( )
D. not( )

130. The __________ traversing method of jQuery returns all ancestor B


elements of the selected element, all the way up to the document's
root element.
A. parent( )
B. parents()
C. parentsUntil()

131. Which of the following jQuery method is used to sets or get one or B
more style properties for the selected elements?
A. html( )
B. css()
C. val()
D. addCSS()

You might also like