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.
What is the comma ( , ) operator?
It separates function arguments and other lists of items.
What is the “ new “ and the “ -> “ operator?
They’re used to instantiate a class and access class members.
What is the Ternary Operator?
( ?: ) Question mark colon
Its similar to an if-else statement.
Example:
($grade >= 50 ? ‘Passed’ : ‘Failed’);
What is the Error Suppression operator?
( @ ) or at sign
Can be used in front of any expression; Anything that generates or has a value.
Example:
$a = @(57/0);
Without the @ operator, this line generates a divide-by-zero warning.
What is the Execution Operator?
( ` ` ) or backticks
Php attempts to execute whatever is contained between the backticks as a command at the server’s command line.
Example:
$out = ls -la
;
echo ‘<pre>’.$out.’</pre>’;
What is instanceof ?
( instanceof ) is a Type Operator. Allows you to check whether an object is an instance of a particular class.
Example: class sampleClass(); $myObject = new sampleClass(); if ($myOject instanceof sampleClass) echo "myObject is an instance of sampleClass";
'; ```
';
';
';
Regular Customer
; break; case "b" : echo "Customer referred by TV
; break; case "c" : echo "Customer referred by phone
; break; default : echo "We do no know how this customer found us
"; } ```"; } while ($num < 1); This will only run once because 100 will never be less then 1.