Sei sulla pagina 1di 34

IP 621

Unit 1: Introduction to PHP

1. PHP stands for


a. Hpertext preprocessor
b. Hypertext processor
c. HTML preprocessor
d. HTML processor

ANS: a

2. PHP scripts are used in


a. Server-side scripting
b. Command line scripting
c. Client-side GUI applications
d. All of the above

ANS: a

3. Which of the following is not true?


a. PHP can be used to develop web applications.
b. PHP makes a website dynamic.
c. PHP applications cannot be compiled.
d. PHP cannot be embedded into html

ANS: d

4. PHP is a widely used _______ scripting language that is especially suited for web development
and can be embedded into html
a. Open source general purpose
b. Proprietary general purpose
c. Open source special purpose
d. Proprietary special purpose

ANS: a

5. PHP files have a default file extension of_________


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

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

ANS: d

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)

ANS: c

8. PHP scripts are executed on __________________


a. ISP computer
b. Client computer
c. Server computer
d. Depends on script

ANS: c

9. In PHP each statement must end with _____________


a. . (dot)
b. ;(semi-colon)
c. /(slash)
d. :(colon)

ANS: b

10. PHP configuration settings are maintained in


a. pws-php5cgi.reg
b. php.ini
c. httpd.conf
d. httpd-info.conf

ANS: b
11. PHP is a _____________ typed language
a. User
b. Loosely
c. Server
d. System

ANS: b

12. What does the PHP interpreter do?


a. It translates User language to System Language
b. It creates connection between ISP and Server
c. It processes the HTML and PHP files
d. All of the above

ANS: c

13. How are PHP files accessed?


a. Through the Web Browser
b. Through HTML files
c. Through the Web Server
d. All of the above

ANS: c

14. What will be the output of the following PHP code?


<?php
"Hello World"
?>
a. Error
b. Hello World
c. Nothing
d. Missing semicolon error

ANS: c
15. What will be the output of the following PHP code ?
<?php
# echo "Hello world";
echo "# Hello world";

?>

a. # Hello world
b. Hello world# Hello world
c. Hello world
d. Error

ANS: a

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


<?php
/*
echo "Hello world";
*/
?>
a. Hello world
b. Nothing
c. error
d. /*
Hello world
*/

ANS: b

17. PHP is an interpreted language,


a. True
b. False

ANS: a

18. Which statement is not true about PHP?


a. PHP is a server side scripting language
b. PHP is a client side scripting language
c. PHP is used to make websites dynamic and interactive
d. PHP code can be imbedded within HTML code

ANS: b
19. Which option does not apply to the php.ini file?
a. The php.ini file can be used to specify the maximum size of files that a user can upload
b. The php.ini file can be used to set the folder and cookie settings
c. The php.ini file is read by the PHP engine when PHP starts
d. The php.ini file is used to close all internet connections

ANS: d

20. PHP can run on different platforms e.g. Windows and Linux
a. True
b. False

ANS: a

21. Which extension is the correct php file extension?


a. .php
b. .pxhtml
c. .php33a
d. .phxml4

ANS: a

22. Look at the following code and determine what will be displayed in the browser:
<?php
echo “Hello World 1”;
// echo “Hello World 2”;
?>
a. Hello World 1 Hello World 2
b. Hello World 2
c. Hello World 1
d. Hello World 2 Hello World 1

ANS: c

23. You can use HTML tags within an echo string?


a. True
b. False

ANS: a
24. From the following php scripting block, what will be displayed in the browser:
<?php
$aVariable = “Hello Robert”;
echo “$aVariable”;
?>
a. Hello
b. aVariable
c. Hello Robert
d. None of the above

ANS: c

25. PHP is an open source software


a. True
b. False

ANS: a

26. What is the difference between print() and echo()?


a. print() can be used as part of an expression, while echo() cannot
b. echo() can be used as part of an expression, while print() cannot
c. echo() can be used in the CLI version of PHP, while print() cannot
d. both A and B

ANS: a

27. A script is a _____________


a. Program or sequence of instructions that is interpreted or carried out by processor
directly
b. Program or sequence of instruction that is interpreted or carried out by another
program
c. Program or sequence of instruction that is interpreted or carried out by web server only
d. None of above

ANS: b
28. What will be the output of the following code block? Assume today is 2009-5-19:19:2:45:32 pm
<?php
$today = date("F j, Y, g:i a");
?>
a. may 19,09,2:45:32 PM
b. May 19, 2009, 2:45 pm
c. May 19,2009,14:45:32 pm
d. May 19,2009,14:45:32 PM

ANS: b

29. Trace the false statement from the following


a. Any code found within an included file will inherit the variable scope of the location of
its caller
b. Because the included code will be embedded in a PHP execution block, the PHP
execution block, the PHP escape tags (<?php?> aren’t required on the file to be
included.
c. For the inclusion of remote files the allow-url-pope must be enabled ad URL wrapper
must be supported
d. Including a file produces the same result as copying the data from the file specified into
the location in which the statement appears.

ANS: b

30. What will be the output of the following date() function?


<?php
$date="2009-5-19";
$time="14:31:38";
$datetime=$date.$time;
echo date("Y-m-d:H:i:s",strtotime($datetime));
?>
a. 2009-5-19:14:31:38
b. 2009-5-19:2:31:38
c. 19-5-2009:2:31:38
d. 19/5/2009:14:31:38

ANS: a
31. PHP code is directly embedded into XHTML document?
a. True
b. False

ANS: a

Unit 2: PHP Language basics

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

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

ANS: b

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


a. \r
b. \n
c. /n
d. /r

ANS: b
35. What will be the output of the following PHP code?
<?php
$num = 10;
echo 'What is her age? \n She is $num years old';
?>
a. What is her age? \n She is $num years old
b. What is her age?
She is $num years old
c. What is her age? She is 10 years old
d. What is her age?
She is 10 years old

ANS: a

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


a. 12
b. 1
c. Error
d. 5

ANS: d

37. In PHP language variable names start with ____________


a. !(Exclamation)
b. &(Ampersand)
c. *(Asterisk)
d. $(Dollar)

ANS: d

38. In PHP one needs to declare variables before assigning values to them.
a. True
b. False
c. Depends on the server
d. Depends on the site

ANS: d

39. Which of the following is the Concatenation operator in PHP?


a. +(Plus)
b. .(dot)
c. &(Apersand)
d. %(Percent)

ANS: b
40. How to define a variable in PHP
a. $variable_name = value
b. $variable_name = value;
c. $variable_name == value;
d. $variable_name as value;

ANS: b

41. What is the result of combining a string with another data type in PHP?
a. int
b. float
c. string
d. double

ANS: c

42. Variables in PHP are case sensitive


a. True
b. False
c. Depends on server
d. Depends on browser

ANS: a

43. What will be the output of the following PHP code?


<?php
$a = 10;
echo ++$a;
echo $a++;
echo $a;
echo ++$a;
?>
a. 11111213
b. 11121213
c. 11111212
d. 11111112

ANS: a
44. What will be the output of the following PHP Code?
<?php
$a = 12;
--$a;
Echo $a++;
?>
a. 11
b. 12
c. 10
d. Error

ANS: a

45. Trace the odd data type


a. floats
b. integer
c. doubles
d. Real number

ANS: d

46. In php string data are


a. delimited by single quote
b. delimited by double quote
c. delimited by <<< identifier
d. All of above

ANS: b

47. Which data types are treated as arrays?


a. Integer
b. Float
c. String
d. Booleans

ANS: c

48. When defining identifier in PHP you should remember that


a. Identifiers are case sensitive. So $result is different than $Result
b. Identifiers can be any length
c. Both of above
d. None of above

ANS: c
49. Identify the invalid identifier
a. my_function
b. size
c. _some word
d. This&that

ANS: d

50. The left associative dot operator (.) is used in PHP for
a. multiplication
b. concatenation
c. separate object and its member
d. delimeter

ANS: b

51. Which of following are compound data types?


a. Array
b. Objects
c. Both of the above
d. None of the above

ANS: c

52. What will be the output of the following PHP code?


<?php
$color = "red";
$color = "green";
echo "$color";
?>
a. red
b. green
c. red green
d. error

ANS: b
53. What will be the output of the following PHP code?
<?php
$i = 0; $j = 1; $k = 2;
print !(($i + $k) < ($j - $k));
?>
a. 1
b. true
c. false
d. 0

ANS: a

54. What will be the output of the following PHP code?


<?php
define("GREETING", "PHP is a scripting language", true);
echo GREETING;
echo "<br>"
echo GREETING;
?>
a. PHP is a scripting language
b. GREETING
GREEtING
c. GREETING
d. PHP is a scripting language
PHP is a scripting language

ANS: d

55. What will be the output of the following PHP code?


<?php
$a = 5;
$b = 5;
echo ($a === $b);
?>
a. 5 === 5
b. Error
c. 1
d. False

ANS: c
56. An initialized variable in PHP is given a default value of ____________
a. 0 (zero)
b. null
c. default
d. None of the above

ANS: b

57. PHP allows you to use variables at any point of the script without having explicitly declared them
prior
a. True
b. False

ANS: a

58. Which two compound data types are supported by PHP?


a. Array and Integer
b. Array and float
c. Float and Integer
d. Array and Object

ANS: d

59. Finally, PHP supports two special data types, so called because they don’t contain scalar or
compound data. Identify two special data types supported by PHP
a. Array and Object
b. Integer and Float
c. Resource and Null
d. None of the above

ANS: c
60. Consider the following code block:
<php
$testVar;
$testVar = “moodley”;
$testVar = 89.6;
$testVar = 67;
echo gettype($testVar);
?>
The output of this program is:
a. error
b. String
c. Integer
d. Double

ANS: c

61. Consider the following code block

<?php
$test_var = 8.23;
settype( $test_var, “integer” );
echo $test_var . “ < br / > ”;
?>

The output of this program is _____________


a. 8.23
b. 8
c. 8.0
d. 8.2

ANS: b

62. All of the following can be used as identifiers (variable names) in PHP except __________
a. $_account_name
b. $23Account
c. $aVeryLongVariableName
d. $abc123

ANS: b
63. What is the output of the following code block?
<?php
$x = 6;
$y = 13;
echo $x + $y;
?>
a. 19
b. xy
c. 613
d. $x+$y

ANS: a

64. Which of the following is the incorrect way to declare a PHP variable?
a. $aVariable;
b. $a_Variable = 9;
c. $AVariable;
d. $a Variable;

ANS: d

65. PHP variables need to be declared before adding a value to it?


a. True
b. False

ANS: b

66. What data type will PHP automatically convert the following variable to? $aVariable = 99;
a. integer (a number variable)
b. string (a text variable)

ANS: a

67. Which of the following is the incorrect way to declare a PHP variable?
a. $a_Number = 9
b. $a_Number = 9;
c. $a_Num = 9;
d. $aNumber = 9;

ANS: a
68. Which of the following is the incorrect way to echo a variable?
a. echo “$aVariable”;
b. echo $aVariable;
c. All of the above
d. None of the above

ANS: c

69. If the variable $x = 10; what will $x equal if it is incremented, that is, if I write $x++; what value
will $x contain after it has been incremented?
a. 9
b. 10
c. 11
d. 12

ANS: c

70. The following example $a -= $b; is the same as?


a. $b = $a – $b;
b. $a = $a – $b;
c. $a = $b – $a;
d. $b = $b – $a;

ANS: b

71. The logical operator && stands for?


a. OR
b. AND
c. NOT
d. None of the above

ANS: b

72. The logical operator || stands for?


a. OR
b. AND
c. NOT
d. None of the above

ANS: a
73. The following condition will return TRUE or FALSE:
(4 >= 4 && 8 < 1)
a. TRUE
b. FALSE

ANS: b

74. The following condition will return TRUE or FALSE


((4 >= 4 && 8 < 1) || (44 == 33 || 5 > 3))
a. TRUE
b. FALSE

ANS: a

75. What will be displayed in a browser when the following PHP code is executed?
<?php

if (8 >= 7) {

echo "Hello World";

?>
a. Hello World
b. Nothing Will Be Displayed
c. True
d. TrueHello World

ANS: a

76. Which of the following is correct about variable naming rules?


a. Variable names must begin with a letter or underscore character.
b. A variable name can consist of numbers, letters, underscores.
c. You cannot use characters like + , - , % , ( , ) . & , etc in a variable name.
d. All of the above.

ANS: d
77. Which of the following is correct about constants?
a. To define a constant you have to use define() function.
b. To retrieve the value of a constant, you have to simply specify its name.
c. Both of the above.
d. None of the above.

ANS: c

78. Which of the following is correct about constants vs variables in PHP?


a. There is no need to write a dollar sign ($) before a constant, where as in Variable one
has to write a dollar sign.
b. Constants cannot be defined by simple assignment, they may only be defined using the
define() function.
c. Both of the above.
d. None of the above.

ANS: c

79. How does the identity operator === compare two values?
a. It converts them to a common compatible data type and then compares the
resulting values
b. It returns True only if they are both of the same type and value
c. If the two values are strings, it performs a lexical comparison
d. bases its comparison on the C strcmp function exclusively

ANS: a

80. Variables always start with a _______ in PHP


a. Pond-sign
b. Yen-sign
c. Dollar-sign
d. None of the Above

ANS: c

81. Which of the following is not valid PHP code?


a. $_10
b. ${?MyVar?}
c. &$something
d. $10_somethings

ANS; d
82. How would you add 1 to the variable $count?
a. incr count;
b. $count++;
c. $count =+1
d. incr $count;

ANS: b

83. PHP variables are _____________


a. Multitype variables
b. Double type variables
c. Single type variable
d. Trible type variables

ANS: a

84. You can define a constant by using the define() function. Once a constant is defined
a. It can never be changed or undefined
b. It can never be changed but can be undefined
c. It can be changed but cannot be undefined
d. It can be changed and can be undefined

ANS: a

Unit 3: Decisions and control structures in PHP

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

ANS: d
86. What will be the output of the following PHP code?

<?php
$team = "arsenal";
switch ($team) {
case "manu":
echo "I love man u";
case "arsenal":
echo "I love arsenal";
case "manc":
echo "I love manc"; }
?>
a. I love arsenal
b. Error
c. I love arsenalI love manc
d. I love arsenalI love mancI love manu

ANS: c

87. 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
88. What will be the output of the following PHP code?

<?php

$x;
if ($x)
print "hi" ;
else
print "how are u";
?>
a. how are u
b. hi
c. Error
d. No output

ANS: b

89. What will be the output of the following PHP code ?


<?php
$x = 10;
$y = 20;
if ($x > $y + $y != 3)
print "hi" ;
else
print "how are u";
?>
a. how are u
b. hi
c. Error
d. No output

ANS: b
90. What will be the output of the following PHP code?
<?php
$x = 1;
if ($x == 2)
print "hi" ;
else if($x = 2)
print $x;
else
print "how are u";
?>
a. error
b. 2
c. hi
d. how are u

ANS: b

91. What will be the output of the following PHP code?


<?php
$a = 100;
if ($a > 10)
printf("M.S. Dhoni");
else if ($a > 20)
printf("M.E.K Hussey");
else if($a > 30)
printf("A.B. de villiers");
?>
a. M.S.Dhoni
b. M.E.K.Hussey
c. M.S.Dhoni
M.E.K.Hussey
A.B.de villiers
d. no output

ANS: a
92. What will be the output of the following PHP code ?
<?php
$i = 0
do
{
print "hi";
$i++;
}
while ($i != 3);
?>
a. hi
hi
b. hi
c. hi
hi
hi
hi
d. no output

ANS: c

93. What will be the output of the following PHP code ?


<?php
$i = 5;
while (--$i > 0)
{
$i++; print $i; print "hello";
}
?>
a. 4hello4hello4hello4hello4hello…..infinite
b. 5hello5hello5hello5hello5hello…..infinite
c. no output
d. error

ANS: a
94. What will be the output of the following PHP code?
<?php
$i = 5;
while (--$i > 0 && ++$i)
{
print $i;
}
?>
a. 5
b. 555555555…infinitely
c. 54321
d. error

ANS: b

95. What will be the output of the following PHP code?


<?php
$a = "1";
switch($a)
{
case 1:
break;
print "hi";
case 2:
print "hello";
break;
default:
print "hi1";
}
?>
a. hihellohi1
b. no output
c. hihi1
d. hi1

ANS: b
96. What will be displayed in a browser when the following PHP code is executed:
<?php
if (8 >= 7 && "Tom" == "Rose") {
echo "Hello World";
}
?>
a. Hello World
b. Nothing Will Be Displayed

ANS: b

97. What will be displayed in a browser when the following PHP code is executed:
<?php
if (8 >= 7 || "Tom" == "Rose") {
echo "Hello World";
}
?>
a. Hello World
b. Nothing Will Be Displayed

ANS: a

98. The PHP If Statement will only execute the code within it’s curly braces if the if condition is
FALSE?
a. True
b. False

ANS: b

99. What will be displayed in a browser when the following PHP code is executed:
<?php
if (8 <= 7) {
echo "Hello World";
}
else {
echo "Hello YouTube";
}
?>
a. Hello World
b. Hello YouTube
c. Hello World Hello YouTube
d. Nothing Will Be Displayed

ANS: b
100. The PHP If Else Statement can execute the code within the if and else segments at the same
time?
a. True
b. False

ANS: b

101. What will be displayed in a browser when the following PHP code is executed:
<?php
$bookColor = "red";
$bookName = "The PHP Basics";
if ($bookColor == "red" && $bookName == "Steve Jobs") {
echo "You have the wrong book";
}
else {
echo "You might have the right book";
}
?>
a. You have the wrong book
b. You might have the right book
c. Nothing Will Be Displayed
d. False

ANS: b
102. What will be displayed in a browser when the following PHP code is executed:
<?php
$x = 6;
$y = 4;
$sum = $x + $y; //sum = 10
$ten = "Ten";
if ($sum >= 10 && $ten == "Ten") {
$answer = "Correct";
echo "Your answer is: $answer";
}
else {
$answer = "Incorrect";
echo "Your answer is: $answer";
}
?>
a. Your answer is: Incorrect
b. Your answer is: $answer
c. Your answer is: Correct
d. Nothing Will Be Displayed

ANS: c

103. Which of the following cases is a correct way to write a case for a switch statement?
a. case “Mark”;
b. case “Mark”::
c. case “Mark”:
d. case “Mark”{

ANS: c

104. The default case is executed if all the other cases for a switch statement evaluate to false?
a. True
b. False

ANS: a
105. What will be displayed in a browser when the following PHP code is executed:
<?php
$variable = 2;
switch ($variable) {
case 1:
echo "Hello World";
break;
default:
echo "Hello Channel";
break;
}
?>
a. Hello World
b. Hello Channel
c. Nothing Will Be Displayed
d. $variable

ANS: b

106. What will be displayed in a browser when the following PHP code is executed:
<?php
$variable = 1;
switch ($variable) {
case 1:
echo "Hello World";
default:
echo "Hello Channel";
break;
}
?>
a. Hello World
b. Hello Channel
c. Hello WorldHello Channel
d. Nothing Will Be Displayed

ANS: c
107. What is missing from case 2 in the switch statement below?
<?php
$variable = 1;
switch ($variable) {
case 1:
echo "Hello World";
break;
case 2:
echo "Hello Tom";
default:
echo "Hello Robert";
break;
}
?>
a. break:
b. break()
c. break;
d. None of the above

ANS: c

108. A while loop will continue to execute a segment of code until its condition evaluates to
false?
a. True
b. False

ANS: a

109. A while loop is preferred when having to carry out a repetitive operation?
a. True
b. False

ANS: a
110. What will be displayed in a browser when the following PHP code is executed:
<?php
$counter = 1;
while ($counter <= 5) {
$counter++;
}
echo "Counter is: $counter";
?>
a. Counter is: 1
b. Counter is: 5
c. Counter is: 4
d. Counter is: 6

ANS: d

111. What will be displayed in a browser when the following PHP code is executed:
<?php
$counter = 6;
while ($counter != 3) {
echo "Hello World | ";
$counter--;
}
?>
a. Hello World | Hello World |
b. Hello World | Hello World | Hello World |
c. Hello World | Hello World | Hello World | Hello World |
d. None of the above

ANS: b

112. What will be displayed in a browser when the following PHP code is executed:
<?php
$counter = 3;
while ($counter != 3) {
echo "Hello World | ";
$counter--;
} ?>
a. Hello World | Hello World
b. Hello World | Hello World | Hello World
c. Hello World | Hello World | Hello World | Hello World
d. None of the above

ANS: d
113. A do while loop will execute a segment of code at least one time?
a. True
b. False

ANS: a

114. A do while loop will check the while condition before executing the segment of code
between the curly braces?
a. True
b. False

ANS: b

115. Is the following a correct example for a PHP do while loop?


<?php
$counter = 1;
do while ($counter < 5);{
$counter++;
}
echo "Counter is: $counter";
?>
a. Yes
b. No

ANS: b

116. What will be displayed in a browser when the following PHP code is executed:
<?php
$counter = 1;
do while ($counter < 5);{
$counter++;
}
echo "Counter is: $counter";
?>
a. Counter is: 4
b. Counter is: 5
c. Counter is: 2
d. None of the above

ANS: d
117. What will be displayed in a browser when the following PHP code is executed:
<?php
$counter = 1;
do {
$counter++;
} while ($counter < 0);
echo "Counter is: $counter";
?>
a. Counter is: 4
b. Counter is: 5
c. Counter is: 2
d. None of the above

ANS: c

118. A for loop contains an initializing expression, a condition statement expression, and an
increment expression?
a. True
b. False

ANS: a

119. A for loop will check the condition statement before executing the segment of code
between the curly braces?
a. True
b. False

ANS: a

120. What will be displayed in a browser when the following PHP code is executed?
<?php
for ($counter = 20; $counter < 10; $counter++){
echo "Hello Robert ";
}
echo "Counter is: $counter";
?>
a. Hello Robert
b. Counter is: 20
c. Hello Robert Counter is: 22
d. Hello Robert Hello Robert Counter is: 22

ANS: b
121. What will be displayed in a browser when the following PHP code is executed:
<?php
for ($counter = 15; $counter != 10; $counter--){
echo "Hello ";
}
?>
a. Hello Hello
b. Hello Hello Hello
c. Hello Hello Hello Hello Hello
d. None of the above

ANS: c

122. What will be displayed in a browser when the following PHP code is executed:
<?php
for ($counter = 10; $counter < 10; $counter = $counter + 5){
echo "Hello";
}
?>
a. Hello Hello Hello Hello Hello
b. Hello Hello Hello
c. Hello
d. None of the above

ANS: d

123. Which of the following keyword terminates the for loop or switch statement and transfers
execution to the statement immediately following the for loop or switch?
a. break
b. continue
c. All of the above
d. None of the above

ANS: a

124. Which of the following keyword causes the loop to skip the remainder of its body and
immediately retest its condition prior to reiterating?
a. break
b. continue
c. All of the above
d. None of the above

ANS: b

Potrebbero piacerti anche