PHP Midterm Exam Questions and
Answers
Select the answer that is NOT a PHP data type.
Undefined
Array
Float
NULL - Answer-Undefined
Which statement is often used to display output in PHP?
printScreen
screenPrint
echo
display - Answer-echo
If you need to know the data type and value of a PHP variable, you should use the _______________
function.
var_dump
toString
,typeof
type_of - Answer-var_dump
When you create PHP constant values, you can indicate if the constant is case-sensitive.
True
False - Answer-True
PHP is currently utilized in a majority of websites.
True
False - Answer-True
To generate a random number in PHP, you should use the __________ function.
serialize
rand
random
randNum - Answer-rand
PHP variable names start with which symbol?
!
$
&
,# - Answer-$
PHP code is executed in the browser.
True
False - Answer-False
PHP variable names are case-sensitive.
True
False - Answer-True
Like JavaScript, you can concatenate PHP strings with the + operator
True
False - Answer-False
function addCoffee(&$word) { $word = $word . "coffee"; }
$myWord = "Good";
addCoffee($myWord);
echo $myWord;
What will the output be?
Good coffee
, Good
Error! There's an ampersand in the parameter.
Goodcoffee - Answer-Goodcoffee
$x = 5; $y = 10;
Select the if statement that will output "Hello!" when $x is equal to 5 or when $y is equal to 10, but will
not create output if both are true.
if ($x === 5 Or $y === 10) { echo "Hello!"; }
if ($x === 5 xor $y === 10) { echo "Hello!"; }
if ($x === 5 || $y === 10) { echo "Hello!"; }
if ($x === 5 && $y === 10) { echo "Hello!"; } - Answer-if ($x === 5 xor $y === 10) { echo "Hello!"; }
When constructing a Switch statement, every case should end with a _________________ until you
reach the default code to be executed.
conditional
exception
break
continue - Answer-break
By default, PHP is a strictly typed language.
True
False - Answer-False
I am concerned that my PHP form may be easily hacked with XSS. I am going to use the
htmlspecialchars() function to prevent this. What does htmlspecialchars() do?
Answers
Select the answer that is NOT a PHP data type.
Undefined
Array
Float
NULL - Answer-Undefined
Which statement is often used to display output in PHP?
printScreen
screenPrint
echo
display - Answer-echo
If you need to know the data type and value of a PHP variable, you should use the _______________
function.
var_dump
toString
,typeof
type_of - Answer-var_dump
When you create PHP constant values, you can indicate if the constant is case-sensitive.
True
False - Answer-True
PHP is currently utilized in a majority of websites.
True
False - Answer-True
To generate a random number in PHP, you should use the __________ function.
serialize
rand
random
randNum - Answer-rand
PHP variable names start with which symbol?
!
$
&
,# - Answer-$
PHP code is executed in the browser.
True
False - Answer-False
PHP variable names are case-sensitive.
True
False - Answer-True
Like JavaScript, you can concatenate PHP strings with the + operator
True
False - Answer-False
function addCoffee(&$word) { $word = $word . "coffee"; }
$myWord = "Good";
addCoffee($myWord);
echo $myWord;
What will the output be?
Good coffee
, Good
Error! There's an ampersand in the parameter.
Goodcoffee - Answer-Goodcoffee
$x = 5; $y = 10;
Select the if statement that will output "Hello!" when $x is equal to 5 or when $y is equal to 10, but will
not create output if both are true.
if ($x === 5 Or $y === 10) { echo "Hello!"; }
if ($x === 5 xor $y === 10) { echo "Hello!"; }
if ($x === 5 || $y === 10) { echo "Hello!"; }
if ($x === 5 && $y === 10) { echo "Hello!"; } - Answer-if ($x === 5 xor $y === 10) { echo "Hello!"; }
When constructing a Switch statement, every case should end with a _________________ until you
reach the default code to be executed.
conditional
exception
break
continue - Answer-break
By default, PHP is a strictly typed language.
True
False - Answer-False
I am concerned that my PHP form may be easily hacked with XSS. I am going to use the
htmlspecialchars() function to prevent this. What does htmlspecialchars() do?