Chapter 4 - Expressions and Control Flow in PHP Flashcards

1
Q

What is an expression?

A

A combination of values, variables, operators and functions that results in a value.

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

What is a unary operator?

A

Takes a single operand.

Eg. $a++ or -$a

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

What is a binary operator?

A

Represents the bulk of php operators, including addition, subtraction, multiplication and division.

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

What is a binary operator?

A

Represents the bulk of php operators, including addition, subtraction, multiplication and division.

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

What is a literal?

A

The simplest form of an expression, which simply means something that evaluates itself, such as the number 15 or the string “Hello”.

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

What is a ternary operator?

A

Takes the form ? x: y. It’s a terse, single-line if statement that chooses between two expressions, depending on the result of a third one.

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

What is the associativity of

A

None

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

What is the associativity of (string) - cast to a string?

A

Right

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

What is the associativity of % Modulus?

A

Left

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

What does a relational operator do?

A

Tests two operands and returns a Boolean result of either True or False.

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

what are the three types of relational operators?

A

Equality
Comparison
Logical

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

What is a conditional?

A

Conditionals alter program flow. They enable you to ask questions about certain things and respond to the answers you get in different ways.

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

Give an example of PHP code for an if - else statement:

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

What does the SWITCH statement do?

A

It is useful in cases in which one variable or the result of an expression can have multiple values, which should each trigger a different function.

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

What does the ? Operator do?

A

It passes an expression that it must evalulate, along with two statements to execute. One for when the expression evaluates to TRUE and the other for when it is FALSE.

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

What is the difference between implicit and explicit casting?

A

PHP allows you to declare a var and its type simply by using it. It also automatically converts values from one type to another whenever required. This is called IMPLICIT CASTING.

Sometimes this might not be what you want. What if you want something else, you can cast the type to be a specific int instead of double. This is EXPLICIT CASTING.

17
Q

What does the ? Operator do?

A

It passes an expression that it must evaluate, along with two statements to execute. One for when the expression evaluates to TRUE and the other for when it is FALSE.

18
Q

What is the difference between implicit and explicit casting?

A

PHP allows you to declare a var and its type simply by using it. It also automatically converts values from one type to another whenever required. This is called IMPLICIT CASTING.

Sometimes this might not be what you want. What if you want something else, you can cast the type to be a specific int instead of double. This is EXPLICIT CASTING.

19
Q

What is PHP Dynamic Linking?

A

Splitting a website into different components makes for a much more useable code.

20
Q

What actual underlying values are represented by TRUE and FALSE?

A

In PHP, TRUE represents the value 1 and FALSE represents NULL, which can be thought of as “nothing” and is output as an empty string.

21
Q

What are the simplest two forms of expression?

A

Literals such as numbers and strings

Variables, which simply evaluate themselves.

22
Q

What is the difference between unary, binary and ternary operators?

A

The difference between unary, binary and ternary operators is the number of operands each requires - one, two and three, respectively.

23
Q

What is the best way to force your own operator precedence?

A

The best way to force your own operator precedence is to place parantheses around subexpressions to which you wish to give high precedence.

24
Q

What is meant by operator associativity?

A

Operator associativity refers to the direction of processing (left to right or right to left).

25
Q

When would you use the == identity operator?

A

You use the identity operator when you wish to bypass PHP’s automatic operand type changing (also called type casting).

26
Q

Name the three conditional statement types:

A

The three conditional statement types are if, switch, and the ?: operator

27
Q

What command can you use to skip the current iteration of a loop and move on to the next one?

A

To skip the current iteration of a loop and move on to the next one, use a continue statement.

28
Q

Why is a for loop more powerful than a while loop?

A

Loops using for statements are more powerful than while loops, because they support two additional parameters to control the loop handling.

29
Q

How do if and while statements interpret conditional expressions of different data types?

A

Most conditional expressions in if and while statements are literal (or Boolean) and therefore trigger execution when they evaluate to TRUE. Numeric expressions trigger execution when they evaluate to a nonzero value. String expressions trigger execution when they evaluate to a nonempty string. A NULL value is evaluated as false and therefore does not trigger execution.