Chapter 1 - PHP Crash Course Flashcards

0
Q

date(‘h’);

A

12-hour format with leading zeros

Example: 01 through 12

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

date(‘H’);

A

24-hour format with leading zeros

Example: 00-23

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

date(‘i’);

A

Minutes with leading zeros

Example: 00 to 59

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

date(‘j’);

A

Day of the month without leading zeros

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

date(‘F’);

A

Full name of the month

Example: January

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

date(‘Y’);

A

The year using 4 digits

Example: 2015

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you write the date function?

A

date(‘DATE PROPERTIES GO HERE’);

Example: date(‘F jS Y, h:ia’);
Reads: January 6th 2015, 6:14pm

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you access a form variable?

A

$_POST[‘FIELD NAME’];

Example: $_POST[‘tireqty’];

Then you can assign that value to a variable for easy use:

Example: $tireqty = $_POST[‘tireqty’];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you write a form field to the page?

A

echo $tireqty.’ tires<br></br>’;

Or

echo “$tireqty. tires<br></br>”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you use the heredoc syntax for write large strings?

A
echo <<<theEnd
   line 1
   line 2
   line 3
theEnd
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are PHP’s 6 data types?

A
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is type casting?

A

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;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are variable variables?

A

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;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a constant and how do you define one?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you write a combined assignment operator?

A

$a += 5;

Which is the same as:

$a = $a + 5;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a pre-increment or pre-decrement?

A

++$a or –$a

Which has the effect of first incrementing $a by 1 and second, returning the incrementing value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a post-increment or post-decrement?

A

$a++ or $a–

First the value of $a is returned and printed and second, it’s incremented.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is a reference operator?

A

( & ) is the reference operator. It is placed before the variable name and used to avoid making a copy of that variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the comma ( , ) operator?

A

It separates function arguments and other lists of items.

20
Q

What is the “ new “ and the “ -> “ operator?

A

They’re used to instantiate a class and access class members.

21
Q

What is the Ternary Operator?

A

( ?: ) Question mark colon
Its similar to an if-else statement.

Example:
($grade >= 50 ? ‘Passed’ : ‘Failed’);

22
Q

What is the Error Suppression operator?

A

( @ ) 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.

23
Q

What is the Execution Operator?

A

( ` ` ) 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>’;

24
Q

What is instanceof ?

A

( 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";
25
Q

Explain gettype();

A

After passing it a variable it returns the type name (bool, int, double, string, array, object, resource or NULL).

Example:
$a = 56;
echo gettype($a). '<br />';
26
Q

Expain settype();

A

First you add the variable then the type you would like it to change to.

Example:
$a = 56;
settype($a, 'double');
echo gettype($a);
27
Q

is_array();

A

Checks whether the variable is an array.

28
Q

is_double(); is_float(); is_real();

A

All are the same function. Checks whether the variable is a float.

29
Q

is_long(); is_int(); is_integer();

A

All are the same function. Checks whether the variable is an integer.

30
Q

is_string();

A

Checks whether the variable is a string.

31
Q

is_bool();

A

Checks whether the variable is a boolean.

32
Q

is_object();

A

Checks whether the variable is an object.

33
Q

is_resource();

A

Checks whether the variable is a resource.

34
Q

is_null();

A

Checks whether the variable is null.

35
Q

is_scaler();

A

Checks whether the variable is scaler, that is, an integer, boolean, string or float.

36
Q

is_numeric();

A

Checks whether the variable is any kind of number or a numeric string.

37
Q

is_callable();

A

Check whether the variable is the name of a valid function.

38
Q

isset();

A

Its used to test a variable. First you pass it a variable name as an argument and it returns true if it exists and false otherwise. You can also pass in comma separated list of variables and it will check them all.

Example:
echo ‘isset($tireqty) : ‘.isset($tireqty) .’<br></br>’;

39
Q

unset();

A

This function gets rid of the variable it is passed.

Example:
echo ‘unset($tireqty) : ‘.unset($tireqty) .’<br></br>’;

40
Q

empty();

A

Checks to see if a variable exists and has a nonempty, nonzero value. It returns true or false accordingly.

Example:
echo ‘empty($tireqty) : ‘.empty($tireqty) .’<br></br>’;

41
Q

How do you write a switch statement?

A
switch($find) {
   case "a" :
      echo "<p>Regular Customer</p>;
      break;
   case "b" :
      echo "<p>Customer referred by TV</p>;
      break;
   case "c" :
      echo "<p>Customer referred by phone</p>;
      break;
   default :
      echo "<p>We do no know how this customer found us</p>";
}
42
Q

How do you write a while loop?

A

$distance = 50;
while ($distance ;

$distance += 50;
}

43
Q

How do you write a for loop?

A

for ($distance = 50; $distance ;

}

44
Q

How do you write a do…while loop?

A

Do…while loops always run at least once.

$num = 100;
do {
echo $num.”<br></br>”;
} while ($num < 1);

This will only run once because 100 will never be less then 1.

45
Q

What does break; do?

A

Use when you want to stop executing a loop.

46
Q

What does continue; do?

A

Use when you want to jump to the next loop iteration.

47
Q

What does exit; do?

A

Use when you are finished with the entire php script.