Finals Flashcards
Type casting, changes the data type of a variable from one data type to another. True or False?
False
Chapter 1 (page 59)
Casting or Type casting creates an equivalent value in a specific data type for a given value.
Even though PHP automatically assigns the data type of a variable, sometimes you want to ensure that a variable is of the data type or type casting. Type casting or casting copies the value contained in a variable of one data type into a variable of another data type.
When you pass a variable name to the echo statement, you must enclose the variable name in a double quotation marks. True or false?
False
Chapter 1 (page 14)
All Web pages containing PHP code must have an extension on .php. True or false?
True
Chapter 1 (page 2)
The___ function is used to create a constant.
a) define ()
b) create ()
c) describe ()
define ()
Chapter 1 (page28)
A constant contains information that does not
change during the course of program execution
•
Constant names do not begin with a dollar sign
•
Constant names use all uppercase letters
•
Use the define() function to create a constant
define (“
CONSTANT_NAME “, value);
•
The value you pass to the define() function
can be a text string, number, or Boolean value
A(n) ___ is an element’s numeric position within an array.
a) location
b) index
c) indicator
index
Chapter 1 (page 34)
By default, indexes begin with the number
zero (0)
–
An element is referenced by enclosing its index in
brackets at the end of the array name:
$Provinces[1]
Data types that can be assigned only a single value are called ___ types.
a) mono
b) primitive
c) individual
primitive
Chapter 1
The ___ function tests whether a variable contains a numeric data type.
a) is_digit ()
b) is_number ()
c) is_numeric ()
is_numeric ()
Chapter 1 (page 60)
is_numeric () function tests whether a variable contains a numeric data type, whereas the is_string () function test whether a variable contains a string data type
___ are symbols such as the (+) symbol that are used in expressions to manipulate operands.
a) Operators
b) Expressions
c) Literals
Operators
Chapter 1 (page 40)
Operators are symbols such as the addition operator (+) and multiplication operator (*), which are used in expressions to manipulate operands.
One way to ensure that a variable is of the correct data type is through type ___.
a) identifying
b) casting
c) naming
casting
Chapter 1 (page 59)
The ___ operator uses the % symbol to find the remainder of integer division.
a) modulus
b) division
c) arithmetic
modulus
Chapter 1
1 - Standard PHP script delimiters 2 - The element 3 - Short PHP script delimiters 4 - ASP=style script delimiters Which of the above are NOT valid in PHP 7?
a) 3 & 4
b) 2 & 4
c) 2 & 3
d) They are all valid in PHP 7
2 & 4
The element
ASP-style script delimiters
Chapter 1
Which of the following is NOT a valid PHP comment block?
a)
b) /* Comment */
c) // Comment
d) # Comment
a)
this is an HTML comment, not PHP
Chapter 1
Which of the following is PHP?
a) Strongly typed
b) Loosely/weakly typed
c) Neither
d) Both
Loosely/weakly typed - we don’t declare data types, just use identifiers.
Chapter 1
Territories = array(“Nunavut”, “Northwest Territories”, “Yukon Territory”);
What is the index of the element “Yukon Territory”?
a) 0
b) 1
c) 2
d) 3
2
Array indices starts at 0.
Chapter 1
$var = 9;
echo $var %2
What does the above expression resolve to /print?
a) 1
b) 2
c) 4
d) 9
1
Modulus will return the remainder
Chapter 1
$var = 9;
echo $var++;
What does the above expression resolve to /print? (Tricky)
a) 9
b) 10
c) 1
d) This will throw an error
a) 9
$var increments after it prints
Chapter 1
$varA = 9;
$varB = 3;
echo ($varA === $varB || $varA > $varB);
What does the above expression resolve to /print?
a) 0/False
b) 1/True
c) 3
d) This will throw an error
b) 1/True
|| Returns TRUE if either the left operand or right operand returns a value of TRUE, otherwise (neither operand returns a value of TRUE), it returns a value of FALSE
Chapter 1
$varA = 9;
$varB = 3;
echo !($varA === $varB && $varA > $varB);
What does the above expression resolve to /print?
a) 0/False
b) 1/True
c) 3
d) This will throw an error
b) 1/True
&& or AND
Returns TRUE if both the left operand and right operand return a value of TRUE; otherwise it returns a value of FALSE.
Chapter 1
Variable scope refers to the location that a declared variable can be used. True or False?
True
Chapter 2
Variable scope is where in your program a
declared variable can be used
•
A variable’s scope can be either global or local
•
A global variable is one that is declared outside
a function and is available to all parts of your
program
•
A local variable is declared inside a function
and is only available within the function in which
it is declared
What will the following code print? (Note the comment block) $GlobalVariable = "Global variable"; function scopeExample () { // global $GlobalVariable; echo"<p>GlobalVariable </p>"; } scopeExample();
a) “Global Variable”
b) Error
Error
“Undefined Variable
Chapter 2
What will the following code print? $GlobalVariable = 3; function scopeExample() { $GlobalVariable = 5; global $GlobalVariable; $GlobalVariable--; echo $GlobalVariable; } scopeExample();
a) 3
b) 5
c) 2
d) 4
c) 2
The most recent declaration overwrites the variable
Chapter 2
$light="pink"; $speed=0; switch($light ){ case"red":speed = 0; case"yellow":$speed = 10; break; case"green":$speed= 30; break; default:$speed= -1; break; } echo $speed;
What will the following code print?
a) 0
b) 10
c) 30
d) -1
d) -1
Speed changes on the default case which hits because none of the other cases do
Chapter 2
$numbers =array(10,20,30,40,50); for ($i=0; $i <=3; $i++) { $numbers[$i] /= 10; } echo $numbers[4];
What will the following code print?
a) 20
b) 25
c) 40
d) 50
d) 50
$numbers[4] is 50 which is never modified
Chapter 2
You will not receive an error if you attempt to use a foreach statement with any variable types other than arrays. True or False?
False
Chapter 2
foreach Statements
Used to iterate or loop through the elements in
an array
•
Do not require a counter; instead, you specify an
array expression within a set of parentheses
following the foreach keyword
Functions are place within parentheses that follow a parameter name. True or False?
False
Chapter 2
The syntax for defining a function is
A ___ is a variable that increments or decrements with each iteration of a loop statement
a) counter
b) repetitor
c) incrementer/decrementer
d) iterator
a) counter
Chapter 2 (page 96)
A counter is a variable that increments or decrements with each iteration of a loop statement.
Which of the following terms is not associated with the switch statement?
a) switch title
b) executable statement
c) break keyword
d) case label
a) switch title
Chapter 2 (page 92) A switch statement consists of the following components: the keyword switch, an expression, an opening brace, one or more case statements, a default label , and a closing brace. A case statement consists of a case label, the executable statements, and the keyword break.
With many programming languages, global variables are automatically available to all parts of your program, including ___.
a) definitions
b) functions
c) statements
d) declarations
functions
Chapter 2
What will be returned if you use a local variable outside the function in which it is declared?
a) function
b) nothing
c) error message
d) value
c) error message
Chapter 2 (page 82)
When you declare a global variable with the global keyword, you do not need to assign the variable a(n) ___.
a) name
b) definition
c) value
d) function
c) value
Chapter 2 (page 82)
If you do not include code that changes the value used the by the condition expression, your program will be caught in a ___ loop.
a) infinite
b) constant
c) continuous
d) continuing
a) infinite
Chapter 2
Regular expressions are patters that are used for matching and manipulating strings according to specified rules. True or False?
True
Chapter 3
The strtok() function breaks a program into functions. True or False?
False
Chapter 3
strtok() function is used to break a string into smaller strings, called tokens
The opposite of the explode() function is the implode() function. True or False?
True
Chapter 3
The explode() function splits a string into an indexed array at a specified separator
The implode() function combines an array’s elements into a single string, separated by specified characters.
The similar_text () function returns the number ___ two strings have in common.
a) characters
b) sounds
c) numbers
d) words
a) characters
Chapter 3 (page 158)
The similar_text() function are used to determine the similarity between two strings.
The escape sequence to insert a carriage return is ___.
a)
b) \t
c) \r
d) \cr
\r
Chapter 3
The ___ metacharacter is used to allow a string to contain an alternate set of substrings.
a) (!)
b) ()
c) (|)
d) (/)
(|)
Chapter 3
The escape sequence \ inserts a(n) ___.
a) backslash
b) web ink
c) directory
d) comment
backslash
Chapter 3
The most commonly used string counting function is the ___ function, which returns the total number of characters in a string.
a) str_count ()
b) total ()
c) strlen ()
d strpos ()
strlen ()
Chapter 3
The most commonly used string counting function is the strlen () function, which returns the total number of characters in a string.
Escape sequences, such as \n, are counted as one character.
The ___ metacharacter is used to specify a range of values in a character class.
a) (‘)
b) (+)
c) (-)
d) (@)
(@)
Chapter 3
A structure in which variables are placed within curly braces inside of a string is called a ___.
a) complex string syntax
b) function
c) method
d) simple string syntax
complex string syntax
Chapter 3
$str = "hello world"; $str = trim($str); $str = substr($str, 6); $str = ucfirst($str); echo $str;
What will the following code print?
a) hello
b) Hello
c) world
d) World
World
trrm() cuts the beginning and end spaces off (nothing)
substr() returns the substring starting at character 6 (w)
ucfirst() capitalizes the first letter of the string
Chapter 3
preg_match(“/[A-Z]/”, $Input) === 1
What is the above function call matching for against $Input? AKA, what will be indicated if this statement resolves to true?
a) At least one letter
b) At least one uppercase letter
c) No letter
d) No uppercase letters
At least one uppercase letter
[A-Z] indicates upper case
Chapter 3
preg_match(“/^[A-za-z\d]”, $input) === 1
What is the above function call matching for against $Input? AKA, what will be indicated if this statement resolves to true?
a) At least one letter
b) At least one alphanumeric character
c) No alphanumeric characters
d) At least one non-alphanumeric character
At least one non-alphanumeric character
[^] means to exclude the pattern and so we are excluding upper case ([A-Z], lower case ([a-z]) and digits (\d)
Chapter 3
When the form data is submitted using the get method, the form data is appended to the URL specified in the form’s method attribute. True or False?
False
Chapter 4
The “get” method appends the form data to the URL specified in the form’s action attribute.
When the “get” method is used, PHP creates a populates a $_GET array.
From, CC, BCC and Date headers are examples of additional headers. True or False?
True
Chapter 4
When you click a form’s submit button, each field on the form is sent to the Web server as a ___ pair.
a) true/false
b) variable/value
c) name/value
d) yes/ no
name/value
Chapter 4
We can use ___ autoglobal array to refer to the global version of a variable from inside a function.
a) $GLOBALS
b) $_GLOBALS
c) $_GLOBAL
d) $GLOBAL
$GLOBALS
Chapter 4 (page 190)
You must use the global keyword to reference a global variable within the scope of a function. You can also use the $GLOBALS autoglobal array to refer to the global version of a variable from inside a function.
When you use the ___ method to submit form data to the processing script, the form data is appended to the URL specified by the action attribute.
a) get
b) submit
c) post
d) request
get
Chapter 4
The ___ function can be used to ensure that a number has the appropriate number of decimal places.
a) set_decimal()
b) decimal_round()
c) round()
d) round_dec()
round()
Chapter 4
Which of the following is NOT a required argument of the mail() function?
a) recipient(s)
b) message
c) from
d) subject
from
Chapter 4 (page 206)
An e-mail message is sent using the mail() function. The basic syntax for this function is :
mail(recipient(s), subject, message);
Autoglobals or superglobals are predefined ___.
a) constants
b) arrays
c) functions
d) variables
arrays
Chapter 4 (page189)
Autoglobals are associative arrays, which are arrays whose elements are referred to with an alphanumeric key instead of an index number.
The script in the dynamic data section of the Web page template will check the value of the ___ array to determine which page to display, assuming the name being passed is ‘page’.
a) $_GET[‘page’]
b) $_POST[‘page’]
c) $_PAGE[‘page’]
d) $SUBMIT[‘page’]
$_GET[‘page’]
Chapter 4
Name:
How do we get the email value into “$email” after form submission?
a) $email = $_REQUEST[“email”];
b) $email = $_SERVER[“email”];
c) $email = $_POST[“email’”};
d) $email = $_GET[“email”];
$email = $_REQUEST[“email”];
$email = $_POST[“email’”};
Chapter 4
The round() function can be used to ensure that number have the appropriate number of digits after the decimal point, if any. True or False?
True
Chapter 4
You must use the global keyword to reference global variable within the scope function. True or False?
True
Chapter 4 (page 190)
With complex escaping from XHTML, you can close one PHP block, insert some XHTML elements, and then open another PHP block to continue the script. True or False?
False
Chapter 4
The value of the ___ attribute identifies the program on the Web server that will process the form data when the form is submitted.
a) name
b) action
c) id
d) method
action
Chapter 4 (page 192) The value of the action attribute identifies the program on the Web server that will process the form data when the form is submitted.
The additional headers argument needs to be formatted to conform to the syntax of headers in the ___ documentation.
a) Internet Mail Format
b) Internet Email Format
c) Email Message Format
d) Internet Message Format
Internet Message Format
Chapter 4
The ___ autoglobal can be used to access the result from form data sent with both the get and post methods.
a) $_SUBMIT
b) $_FILES
c) $_FORMS
d) $_REQUEST
$_REQUEST
Chapter 4