Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
ANS: a
ANS: a
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
ANS: c
6. A PHP script should start with ___ and end with ___:
a. < php >
b. < ? php ?>
c. <? ?>
d. <?php ?>
ANS: d
ANS: c
ANS: c
ANS: b
ANS: b
11. PHP is a _____________ typed language
a. User
b. Loosely
c. Server
d. System
ANS: b
ANS: c
ANS: c
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
ANS: b
ANS: a
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
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
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
ANS: a
ANS: a
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
ANS: b
ANS: a
31. PHP code is directly embedded into XHTML document?
a. True
b. False
ANS: a
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
ANS: b
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
ANS: d
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
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
ANS: a
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
ANS: d
ANS: b
ANS: c
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
ANS: c
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
ANS: d
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
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
<?php
$test_var = 8.23;
settype( $test_var, “integer” );
echo $test_var . “ < br / > ”;
?>
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
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
ANS: b
ANS: b
ANS: a
73. The following condition will return TRUE or FALSE:
(4 >= 4 && 8 < 1)
a. TRUE
b. FALSE
ANS: b
ANS: a
75. What will be displayed in a browser when the following PHP code is executed?
<?php
if (8 >= 7) {
?>
a. Hello World
b. Nothing Will Be Displayed
c. True
d. TrueHello World
ANS: a
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
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
ANS: c
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
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
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
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
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
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
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
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
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