PHP Chapter 2
False (just a .)
A \. is used to match any single character in a pattern. True or False?
local
A _______ variable is declared inside a function and available to that function.
global
A ______variable is available to all parts of the program and is declared outside a function.
value
A function parameter that is passed by _______ is a local copy of the variable.
reference
A function parameter that is passed by _______ is a reference to the original variable.
c. within the braces of a function definition
A local variable must be declared _________. a. before a function b. after a function c. within the braces of a function definition d. with the local keyword
d. global
A variable that is declared outside a function is called a ________ variable. a. local b. class c. program d. global
c. function
A(n) allows you to treat a related group of PHP commands as a single unit. a. statement b. variable c. function d. event
d. are contained within a command block
An if statement can include multiple statements provided that they . a. execute after the if statement's closing semicolon b. are not contained within a command block c. do not include other if statements d. are contained within a command block
for statement
Combine the initialize, conditional evaluation, and update portions of a loop into a single statement
foreach statement
Combine the initialize, conditional evaluation, and update portions of a loop into a single statement, does not require a counter. Only used with arrays.
a. can be incremented b. can be decremented c. can be changed using any conditional expression
Counter variables ________ . (Choose all that apply.) a. can be incremented b. can be decremented c. can be changed using any conditional expression d. do not change
False
Decision-making structures cannot be nested. True or False?
b. iteration
Each repetition of a looping statement is called a(n) . a. recurrence b. iteration c. duplication d. reexecution
you must use the strict not equal operator (!==)
Explain how to determine whether the strpos() function (and other string functions) actually returns a Boolean value of FALSE and not a 0 representing the first character in a string.
The strtok() function is $variable = strtok(string, separators); .
Explain how to use the strtok() function to break a string into tokens and then navigate through each token.
functions that return a numeric position in a text string and functions that return a character or substring.
Explain the difference between the two types of extraction functions.
"This is a {$Variable} inside a string."
Explain why you need to use complex string syntax. Be sure to include an example.
the character that follows has a special purpose
Explain why you need to use escape characters in strings.
False
Functions must contain parameters. True or False?
default
If none of the options in a switch statement match, the statements after the ______ label are executed.
True
If you include an array within a text string, you need to use complex string syntax. True or False?
False
If you specify an empty string as the second argument of the strtok() function, or if the string does not contain any of the separators you specify, the strtok() function returns a value of FALSE. True or False?
command block
Statements between { and } are called a _____ _______.
True
String comparison operators and most string comparison functions compare individual characters according to their ASCII value. True or False?
do ... while statement
Test the condition *after* executing a series of statements then repeats the execution as long as a given conditional expression evaluates to TRUE
while statements
Tests the condition *prior* to executing the series of statements at each iteration of the loop
language constructs
Th e include, require, include_once, and require_once statements, much like the echo statement, are not considered actual functions, but rather _______ _______that are built into PHP.
include
Th e primary use of the include and require statements is to reuse content on multiple Web pages by allowing you to insert the content of an external file, called an _______file, in your PHP scripts.
if
The following are the three parts of an _____ statement: keyword, (conditional expression), statement;
True
The foreach statement can only be used with arrays. True or False?
d. the value returned by a conditional expression
The switch statement controls program fl ow by executing a specific set of statements, depending on _______. a. the result of an if . . . else statement b. the version of PHP being executed c. whether an if statement executes within a function d. the value returned by a conditional expression
loop
There are four types of _______ statements: -while statements -do...while statements -for statements -foreach statements
b. \'
What is the escape sequence for a single quotation mark? a. \\ b. \' c. \~ d. Th ere is no escape sequence for a single quotation mark.
a. when the for statement begins executing
When is a for statement initialization expression executed? a. when the for statement begins executing b. with each repetition of the for statement c. when the counter variable increments d. when the for statement ends
d. default
When the value returned by a switch statement expression does not match a case label, the statements within the ________ label execute. a. exception b. else c. error d. default
b. else echo "Displayed from an else clause.";
Which is the correct syntax for an else clause? a. else (echo "Displayed from an else clause."; b. else echo "Displayed from an else clause."; c. else "echo 'Displayed from an else clause.'"; d. else; echo "Displayed from an else clause.";
c. ^ and $
Which of the following character pairs match characters at the beginning and end of a string in a regular expression? a. \* and *\ b. || and || c. ^ and $ d. # and #
a. {}
Which of the following character sets do you use for complex string syntax? a. {} b. [] c. () d. // //
d. echo '<p>Welcome to the 'combat zone'! </p>';
Which of the following echo statements is invalid? a. echo "<p>Welcome to the *combat zone*! </p>"; b. echo '<p>Welcome to the "combat zone"! </p>'; c. echo "<p>Welcome to the 'combat zone'! </p>"; d. echo '<p>Welcome to the 'combat zone'! </p>';
c. substr_replace()
Which of the following functions allows you to replace characters within a specified portion of a string? a. str_ireplace() b. str_replace() c. substr_replace() d. strstr()
b. strstr()
Which of the following functions performs a case-sensitive search for specified characters in a string and returns a substring from the last occurrence of the specified characters to the end of the string? a. substr() b. strstr() c. strrchr() d. strpos()
a. strlen()
Which of the following functions returns the length of a string? a. strlen() b. strspn() c. substr_count() d. strcspn()
b. levenshtein()
Which of the following functions returns the number of characters you need to change for two strings to be the same? a. similar_text() b. levenshtein() c. soundex() d. metaphone()
a. str_split() c. explode()
Which of the following functions splits each character in a string into an array element? a. str_split() b. split() c. explode() d. implode()
a. for ($i = 0; $i < 10; ++$i) echo "Displayed from a for statement.";
Which of the following is the correct syntax for a for statement? a. for ($i = 0; $i < 10; ++$i) echo "Displayed from a for statement."; b. for ($i = 0, $i < 10, ++$i) echo "Displayed from a for statement."; c. for { echo "Displayed from a for statement."; } while ($i = 0; $i < 10; ++$i) d. for ($i = 0; $i < 10); echo "Displayed from a for statement."; ++$i;
b. while ($i <= 5) { $echo "<p>$i</p>"; ++$i; }
Which of the following is the correct syntax for a while statement? a. while ($i <= 5, ++$i) { $echo "<p>$i</p>"; } b. while ($i <= 5) { $echo "<p>$i</p>"; ++$i; } c. while ($i <= 5); $echo "<p>$i</p>"; ++$i; d. while ($i <= 5; $echo "<p>$i</p>") { ++$i; }
c. if ($MyVariable == 10) echo "Your variable is equal to 10.";
Which of the following is the correct syntax for an if statement? a. if ($MyVariable == 10); echo "Your variable is equal to 10."; b. if $MyVariable == 10 echo "Your variable is equal to 10."; c. if ($MyVariable == 10) echo "Your variable is equal to 10."; d. if ($MyVariable == 10), echo "Your variable is equal to 10.";
a. . c. .=
Which of the following operators can be used with strings? (Choose all that apply.) a. . b. == c. .= d. +=
a. question mark (?) c. asterisk (*) d. plus sign (+)
Which of the following quantifiers can be used to specify the quantity of a match in a regular expression? (Choose all that apply.) a. question mark (?) b. minus sign (-) c. asterisk (*) d. plus sign (+)
a. break
You can exit a switch statement using a(n) _______ statement. a. break b. end c. quit d. complete