Introduction Flashcards

creating variables and functions - basics

1
Q

how to print

A

echo “string”;

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

new line

A

echo “\n new line”;

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

create a variable

A
$variable_name = "duck";
$variable_number = 103;
$variable_float = -349.4;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

combine string

A

echo “string one “ . “ string two”;

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

print string and variable

A

echo “$variable_name is cool”;

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

string and variable but adding “s or ing”

A

echo “${variable_name}s are cool”;

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

append more to a string variable

A

$variable_name .= “ quack”;

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

create variable copy

A

$variable_copy = $variable_name;

** is a separate variable and will stay the same even if $variable_name gets changed later

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

create variable alias

A

$variable_alias &= $variable_name;

** will always point to $variable_name, even if it is changed

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

math

A
\+ addition
- subtraction
* multiplication
/ division
** exponential 
% modulo (remainder)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

math short syntax

A
Operation:	Long Syntax:	Short Syntax:
Add	        $x = $x + $y	$x += $y
Subtract	$x = $x - $y	$x -= $y
Multiply	$x = $x * $y	$x *= $y
Divide	$x = $x / $y	$x /= $y
Mod	$x = $x % $y	$x %= $y
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

increment operators

A

add $var++;

sub $var–;

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

call multiple functions

A

echo first() . second() . third();

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

function to make permanent changes to a variable

A
function addXPermanently(&$param){
     $param = $param . "X";
     return $param;
}
$word = "Hello";
addXPermanently($word); // Prints: HelloX
echo $word; // Prints: HelloX

** add & to variable

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

access a global parameter in a function

A
$param = 10;
function findParam(){
     global $param;
     return $param * 2; 
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

create a function

A
function helloWorld($param, $var){
        return $param + $var;
}