PHP Set 3 Flashcards

1
Q

What is the syntax of the one line conditional expression?

A

condition ? if_true_expr : if_false_expr

Ternary operator

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

What is the syntax of the switch statement?

A

switch(n) {
case label1:
code if n = label1;
break;
case label2:

default:
code if n is not any label;
}

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

What are the 4 types of loops in PHP?

A
  1. while loops through as long as the given condition is true
  2. do…while loops through code once and then repeats as long as the condition is true
  3. for loops through code a specified number of times
  4. foreach loops through code for each element in an array
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the syntax of a for loop?

A

for($x = 0; $x <= 10; $x++) {

}

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

What is the syntax to declare a function?

A

function name($params) {

}

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

What are the two types of function returns and what are the differences?

A

The two types are coercive (default behaviour) and strict

Coercive mode doesn’t require explicit return type declaration but strict mode does.

To enable stric mode you use the line
declare(strict_types=1);

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

What is output buffering?

A

When the server holds output in a buffer before sending it to the user
This can improve system performance as all output is sent at once and you can access the buffer content without sending it back to the browser in certain situations

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

Why waas output buffering created?

A

To create a seamless transfer from php engine -> apache -> OS -> web user

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

What settings in php.ini allow you to change the behaviour of output control?

A

output_buffering (default 0) enables output buffering for all PHP files by default

output_handler (default NULL) sets the name of the default function that handles output of all output buffers

implicit_flush (default 0) causes output to be sent directly to the browser on each output statement

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

What are the output control functions in PHP code and what do they do?

A

ob_start() creates a new output buffer and adds it to the top of the stack

ob_end_clean() deletes an output buffer without sending its contents to the browser

ob_flush() outputs the contents of the topmost output buffer and clears the buffer

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