Chapter 2 Flashcards
What is wrong with the following example?
<title>Mixing HTML and PHP</title>
<?php </p>
print “
It’s such a perfect day!
“;
?>
Some paragraph text.
The
tag is within the PHP code. You want to try to keep your PHP and styles seprate.
What does a single line of PHP commented code start with?
// This is a singe line of commented PHP code
/ This is how you comment out a single line of PHP code.
True or False
False:
// This is how you comment out a single line of code
How do you comment out several lines of PHP code at once?
/* This is how
you would
comment out
several lines
*/
Is this a good example of commented code?
Yes or no and why?
/*
We are formating phone numbers by stripping all characters
then putting parens around the first 3 numbers adding a
space then grouping the next 3 numbers adding a dash
then the last 4 numbers
*/
No.
You want to be concise.
/*
The business has a requirement that all phone numbers be
formatted with the (123) 123-1234 format
*/
What are the Basic DATA Types that PHP Supports?
- Integers
- Floats
- Strings
- Booleans
What is an Integer?
- An integer is a basic data type php supports.
- Integer is a whole number
$a = 1234; // decimal number
$a = -123; // a negative number
$a = 0123; // octal number (equivalent to 83 decimal)
$a = 0x1A; // hexadecimal number (equivalent to 26 decimal)
$a = 0b11111111; // binary number (equivalent to 255 decimal)
?>
What is are Floats?
- Floats are a basic data type PHP supports.
- Floats are fractions
- Floats are floating point numbers also known as:
- floats
- doubles
- real numbers
$a = 1.234;
$b = 1.2e3;
$c = 7E-10;
?>
What is the difference between Integers and floats?
Integers are whole numbers and floats are fractions
(i.e. 1, 2, 3 vs. 1.5, 2.3, 6.6)
What is a String?
- A basic data type supported by PHP
- a group of characters encolsed in either single or doubl;e quotes.
- Quotes must match
“This is a string”
‘This is also a string’
“This is ‘actually’ a string”
‘This is another “example”’
What does a document method of quoting strings look like?
print <<<eof>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vulputate,</p>
<p>arcu a pellentesque viverra, elit metus pretium dui, nec congue ligula</p>
<p>velit vitae nunc. Aliquam est elit, faucibus vitae tincidunt sed, venenatis</p>
<p>vitae urna. Duis dignissim vel odio ac convallis. Suspendisse sodales viverra</p>
<p>ante, in consectetur nulla finibus a. Integer faucibus auctor ipsum, nec</p>
<p>tincidunt metus mattis id. Morbi non leo tristique, facilisis neque a,</p>
<p>volutpat purus. Class aptent taciti sociosqu ad litora torquent per</p>
<p>conubia nostra, per inceptos himenaeos.</p>
<p>EOF</p>
<p> </p>
</eof>
What does a document metho of quoteing strings start with and end with?
print <<<eof>
<p>This is the string here.</p>
<p>This is the string here.</p>
<p>EOF</p>
<p> </p>
</eof>
A boolean is a number.
True or False
False.
A boolean is a logical value of either true or false.
What is a boolean?
- A basic data type supported by PHP
- a logical value that is either true or false.
What are the Composite DATA Types supported by PHP?
- Arrays
- Objects
- NULL
- Resources
What is an Array?
- A composite type supported by PHP
- An array is a collection of valuse.
What is a NULL Data Type?
- A composite type supported by PHP
- NULL represents a variable with no data value.
What is a respource data type?
- A composite type supported by PHP
- A reference to an external resource
- Used for working with files and databases
What are objects?
- A composite type supported by PHP
- A way of representing every day data.
What is gettype()?
gettype - gets the type of variable
<?php gettype($myVariable); ?>
What kinds of variables does PHP support?
- Predefined
- User-Defined
- Form Variables related to names in an HTML form
What are the valid variable names supposed to start with?
- All variables start with a $ followed by a letter or an _
$name1
$price_tag
$_abc
$Abc_22
$A23
The following are all valid variable names.
True or False?
$10names
box.front
$name#last
A-23
$5
False.
All variables start with a $ followed by a letter or an _
What is String Interpolation?
The process of evaluating a string literal containing one or more placeholders, yielding a result in which the placehoilders are replaced with their corresponding values.
The following is NOT an example of String Interpolation.
True or False.
False.
String Interpolation is the process of evaluating a string literal containing one or more placeholders, yielding a result in which the placehoilders are replaced with their corresponding values.
The following is an exaple of concatenation.
True or false?
<?php echo “Hello $name_variable” ?>
False. It is an example of String Interpolation.
String Interpolation is the process of evaluating a string literal containing one or more placeholders, yielding a result in which the placehoilders are replaced with their corresponding values.
Concatenation looks like this, using a . to concatenate.
<?php echo “Hello” . $name_variable ?>
The following is an exaple of concatenation.
True or false?
<?php echo “Hello” . $name_variable ?</p>
True.
What does Concatenation mean?
Concatenation is the action of linking things together.
In PHP you use the . to concatenate.
<?php echo “Hello” . $name_variable ?>
What are scaler types?
- Boolean
- Integer
- Float (floating-point number aka double)
- String