PHP Set 3 Flashcards
What is the syntax of the one line conditional expression?
condition ? if_true_expr : if_false_expr
Ternary operator
What is the syntax of the switch statement?
switch(n) {
case label1:
code if n = label1;
break;
case label2:
…
default:
code if n is not any label;
}
What are the 4 types of loops in PHP?
- while loops through as long as the given condition is true
- do…while loops through code once and then repeats as long as the condition is true
- for loops through code a specified number of times
- foreach loops through code for each element in an array
What is the syntax of a for loop?
for($x = 0; $x <= 10; $x++) {
…
}
What is the syntax to declare a function?
function name($params) {
…
}
What are the two types of function returns and what are the differences?
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);
What is output buffering?
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
Why waas output buffering created?
To create a seamless transfer from php engine -> apache -> OS -> web user
What settings in php.ini allow you to change the behaviour of output control?
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
What are the output control functions in PHP code and what do they do?
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