Finals Flashcards
(150 cards)
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