Chapter 1 - PHP Crash Course Flashcards
date(‘h’);
12-hour format with leading zeros
Example: 01 through 12
date(‘H’);
24-hour format with leading zeros
Example: 00-23
date(‘i’);
Minutes with leading zeros
Example: 00 to 59
date(‘j’);
Day of the month without leading zeros
date(‘F’);
Full name of the month
Example: January
date(‘Y’);
The year using 4 digits
Example: 2015
How do you write the date function?
date(‘DATE PROPERTIES GO HERE’);
Example: date(‘F jS Y, h:ia’);
Reads: January 6th 2015, 6:14pm
How do you access a form variable?
$_POST[‘FIELD NAME’];
Example: $_POST[‘tireqty’];
Then you can assign that value to a variable for easy use:
Example: $tireqty = $_POST[‘tireqty’];
How do you write a form field to the page?
echo $tireqty.’ tires<br></br>’;
Or
echo “$tireqty. tires<br></br>”;
How do you use the heredoc syntax for write large strings?
echo <<<theEnd line 1 line 2 line 3 theEnd
What are PHP’s 6 data types?
Integer: wholes numbers Float/double: numbers with decimals String: string of characters Boolean: true or false Array: storing multiple data items Object: storing instances of classes
What is type casting?
Taking the value of a variable and interpreting it as another data type and storing that value in another variables.
Example:
$totalqty = 0;
$totalamount = (float)$totalqty;
What are variable variables?
Variable variables let you change the name of a variable dynamically. It works by using the value of one variable as the name of another.
Example:
$varname = ‘tireqty’;
$$varname = 5;
Which is now the same as:
$tireqty = 5;
What is a constant and how do you define one?
It stores a value like a variable, but it’s value is set once and then cannot be changed elsewhere in the script.
Example:
define(‘TIREPRICE’, 100);
*** Constants are set to uppercase by convention, so that it may be easier to point them out
How do you write a combined assignment operator?
$a += 5;
Which is the same as:
$a = $a + 5;
What is a pre-increment or pre-decrement?
++$a or –$a
Which has the effect of first incrementing $a by 1 and second, returning the incrementing value.
What is a post-increment or post-decrement?
$a++ or $a–
First the value of $a is returned and printed and second, it’s incremented.
What is a reference operator?
( & ) is the reference operator. It is placed before the variable name and used to avoid making a copy of that variable.