Week 8 - PHP Part 2 Flashcards

1
Q

What’s the syntax for defining and invoking functions?

A
function "functionname"()
{
what the function does
}

functionname();

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

What are the 3 types of scopes? How are they different?

A

Variable, local and global.

Variable is where a variable can be used. It can be either global (in all functions throughout the code) or local (within a function where it was declared)

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

Superglobals

A

A global variable which is automatically declared by PHP.

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

How do we validate forms with PHP?

A

Forms are validated in PHP using regular expressions, isset and superglobals.

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

How do we implement regular expressions in PHP?

A

By using preg_match.

preg_match(string$pattern, string$subject)

The first parameter determines the pattern, similar to HTML pattern attribute, then the second parameter tells us which string we are going to match the pattern against.

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

isset()

A

Used to check if a variable is assigned before using it.

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

What are examples of superglobals?

A

$_GET and $_POST

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

while Statement

A

An infinite loop that will execute while a condition is true.

$count = 1;
while ($count <= 10) {
echo “The number is $count”;
}

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

do…while Statement

A

A loop statement that will run at least once. Similar to an until statement, where the code will continue running until a certain condition is met.

$count = 2;
do {
echo "<p>The count is equal to" . $count . "</p>";
$count++;
} while ($count < 2);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

for Statement

A

A loop statement which will run for a certain condition evaluating to true, and will end when it becomes false.

$fastFoods = array(“pizza”, “burgers”, “french fries”, “tacos”, “fried chicken”);

for ($count = 0; $count < 5; $count++) {
echo $fastFoods[$count], “<br></br>”;
}

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

foreach Statement

A

An iteration statement used to loop through an array.

foreach ($array_name as $variable_name) {
statements;
}

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

if & if else Statement

A

A conditional statement using else for any alternatives.

if (conditional expression)
statement;
else
statement;

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

switch Statement

A

A conditional statement with multiple cases, and a default statement if none of the conditions match the expression.

switch (expression) {
case label: 
statement(s);
break;
case label:
statement(s);
break;
...
default:
statement(s);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

novalidate

A

A HTML attribute used in the form tag to indicate that the form is not to be validated on submit to check that PHP validation is working.

Ensures that validation isn’t being taken place on HTML side.

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