Generales Flashcards

1
Q

What is a variable

A

Variables are “containers” for storing information.

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

What is a variable

A

Variables are “containers” for storing information.

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

How is defined a variable

A

$name = 0;

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

Rules for PHP variables:

A
  • A variable starts with the $ sign, followed by the name of the variable
  • A variable name must start with a letter or the underscore character
  • A variable name cannot start with a number
  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case-sensitive ($age and $AGE are two different variables)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

PHP Data Types

A
PHP supports the following data types:
•	String
•	Integer
•	Float (floating point numbers - also called double)
•	Boolean
•	Array
•	Object
•	NULL
•	Resource
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

PHP Operators

A

Operators are used to perform operations on variables and values.
PHP divides the operators in the following groups:

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Increment/Decrement operators
  • Logical operators
  • String operators
  • Array operators
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

PHP Conditional Statements

A

In PHP we have the following conditional statements:
• if statement - executes some code if one condition is true
• if…else statement - executes some code if a condition is true and another code if that condition is false
• if…elseif….else statement - executes different codes for more than two conditions
• switch statement - selects one of many blocks of code to be executed

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

PHP - The if…elseif….else Statement

A

if (condition) {
code to be executed if this condition is true;
} elseif (condition) {
code to be executed if this condition is true;
} else {
code to be executed if all conditions are false;
}

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

The PHP switch Statement

A
switch (n) {
    case label1:
        code to be executed if n=label1;
        break;
    case label2:
        code to be executed if n=label2;
        break;
    case label3:
        code to be executed if n=label3;
        break;
    ...
    default:
        code to be executed if n is different from all labels;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When use switch statement

A

Use break to prevent the code from running into the next case automatically. The default statement is used if no match is found.

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

PHP Loops

A

In PHP, we have the following looping statements:

  • while - loops through a block of code as long as the specified condition is true
  • do…while - loops through a block of code once, and then repeats the loop as long as the specified condition is true
  • for - loops through a block of code a specified number of times
  • foreach - loops through a block of code for each element in an array
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
While Loop
The while loop executes a block of code as long as the specified condition is true.
 ";
    $x++;
}
?>
A

The example below first sets a variable $x to 1 ($x = 1). Then, the while loop will continue to run as long as $x is less than, or equal to 5 ($x <= 5). $x will increase by 1 each time the loop runs ($x++):

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

The PHP do…while Loop

The do…while loop will always execute the block of code once, it will then check the condition, and repeat the loop while the specified condition is true.

A

”;
$x++;
} while ($x <= 5);
?>

The example below first sets a variable $x to 1 ($x = 1). Then, the do while loop will write some output, and then increment the variable $x with 1. Then the condition is checked (is $x less than, or equal to 5?), and the loop will continue to run as long as $x is less than, or equal to 5:

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

The PHP for Loop

The for loop is used when you know in advance how many times the script should run.

A

”;
}
?>
The example below displays the numbers from 0 to 10:

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

Parameters of a for loop

A

init counter: Initialize the loop counter value
test counter: Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends.
increment counter: Increases the loop counter value

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

The PHP foreach Loop

The foreach loop works only on arrays, and is used to loop through each key/value pair in an array.

For every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one, until it reaches the last array element.

A

The following example demonstrates a loop that will output the values of the given array ($colors):

”;
}
?>

17
Q

How is defined a variable

A
18
Q

Rules for PHP variables:

A
  • A variable starts with the $ sign, followed by the name of the variable
  • A variable name must start with a letter or the underscore character
  • A variable name cannot start with a number
  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case-sensitive ($age and $AGE are two different variables)
19
Q

PHP Data Types

A
PHP supports the following data types:
•	String
•	Integer
•	Float (floating point numbers - also called double)
•	Boolean
•	Array
•	Object
•	NULL
•	Resource
20
Q

PHP Operators

A

Operators are used to perform operations on variables and values.
PHP divides the operators in the following groups:

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Increment/Decrement operators
  • Logical operators
  • String operators
  • Array operators
21
Q

PHP Conditional Statements

A

In PHP we have the following conditional statements:
• if statement - executes some code if one condition is true
• if…else statement - executes some code if a condition is true and another code if that condition is false
• if…elseif….else statement - executes different codes for more than two conditions
• switch statement - selects one of many blocks of code to be executed

22
Q

PHP - The if…elseif….else Statement

A

if (condition) {
code to be executed if this condition is true;
} elseif (condition) {
code to be executed if this condition is true;
} else {
code to be executed if all conditions are false;
}

23
Q

The PHP switch Statement

A
switch (n) {
    case label1:
        code to be executed if n=label1;
        break;
    case label2:
        code to be executed if n=label2;
        break;
    case label3:
        code to be executed if n=label3;
        break;
    ...
    default:
        code to be executed if n is different from all labels;
}
24
Q

When use switch statement

A

Use break to prevent the code from running into the next case automatically. The default statement is used if no match is found.

25
Q

PHP Loops

A

In PHP, we have the following looping statements:

  • while - loops through a block of code as long as the specified condition is true
  • do…while - loops through a block of code once, and then repeats the loop as long as the specified condition is true
  • for - loops through a block of code a specified number of times
  • foreach - loops through a block of code for each element in an array
26
Q
While Loop
The while loop executes a block of code as long as the specified condition is true.
 ";
    $x++;
}
?>
A

The example below first sets a variable $x to 1 ($x = 1). Then, the while loop will continue to run as long as $x is less than, or equal to 5 ($x <= 5). $x will increase by 1 each time the loop runs ($x++):

27
Q

The PHP do…while Loop

The do…while loop will always execute the block of code once, it will then check the condition, and repeat the loop while the specified condition is true.

A

”;
$x++;
} while ($x <= 5);
?>

The example below first sets a variable $x to 1 ($x = 1). Then, the do while loop will write some output, and then increment the variable $x with 1. Then the condition is checked (is $x less than, or equal to 5?), and the loop will continue to run as long as $x is less than, or equal to 5:

28
Q

The PHP for Loop

The for loop is used when you know in advance how many times the script should run.

A

”;
}
?>
The example below displays the numbers from 0 to 10:

29
Q

Parameters of a for loop

A

init counter: Initialize the loop counter value
test counter: Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends.
increment counter: Increases the loop counter value

30
Q

The PHP foreach Loop

The foreach loop works only on arrays, and is used to loop through each key/value pair in an array.

For every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one, until it reaches the last array element.

A

The following example demonstrates a loop that will output the values of the given array ($colors):

”;
}
?>