Intro to PHP Flashcards

1
Q

echo does what?

A

prints something out

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

what is echo format?

A

echo “text or content to be printed”;

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

what do we put at end of echo statement?

A

a ; so it looks like this: echo “text or content to be printed”;

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

what is a variable?

A

a variable is a container for a value - it can be declared once and then re-used.

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

how do we define a variable?

A

with a $

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

example of a variable?

A

$characterName = “joe” note text uses quotation marks

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

how is php executed?

A

in order

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

What would happen after line 6 and why?
“;
echo “He was $characterAge <br></br>”;
$characterName = “Mike”;
echo “He liked $characterName<br></br>”;
echo “Did not mind being $characterAge”;
?>

A

Name would change to Mike because this line changed the variable:
$characterName = “Mike”;

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

What is the difference between storing text and numbers in a variable?

A

text uses “”, numbers don’t need quotes

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

what is a string in php?

A

a string is plain text

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

a string always needs?

A

””

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

2 types of numbers as variables?

A

integer is a whole number - no decimal point

floating point number or floats has a decimal

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

A boolean

A

is a true or false value

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

Example of a boolean?

A

$isMale = true (can be true or false)

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

the 5 types of variables we just learned?

A
string is text with ""
integer is a whole number
a floating point number or floats has a decimal
a boolean is true or false
null has no value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

a string is?

A

plain text

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

example of printing out a string

A

echo “my string”;

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

can use a variable as a container for a string?

A

yes for example: $phrase = “toasty toes”;

19
Q

how to print the toasty toes?

A

echo $phrase;

20
Q

a function can modify a string

21
Q

what’s a function to change a string to lower case?

A

echo strtolower($phrase);

22
Q

True or False? functions are used to find out information about and to modify strings

23
Q

what’s a function to change a string to upper case?

A

echo strtoupper($phrase);

24
Q

what does a string function do? Can find out information about string or modify a string. They seem to start with?

A

str then the function - so strtolower changes to lower case

25
what do we have to put around the string to use a function?
() - it looks like this: echo strtolower ($phrase);
26
Can you use strtolower on a string that is not a variable? | How? What do we put around the string?
Yes, it would look like this: echo strtolower ("Camel Towing"); We put parens around the string ()
27
What is a function to tell use the length of a string?
strlen. So, strlen ($phrase);
28
What is an index and how is it called?
An index will tell us which character is in which space. This will tell us that the first character is "G" if the string is Giraffe Academy. echo $phrase[0];
29
How is the index numbered? 0 is 1, 1 is 2 and so on. Giraffe?
Giraffe 0=G 1=i 2=r and so on.
30
Also can use index function on plain strings: "Mike"
echo "Mike"[2]; will print out k
31
What would this do? $phrase = "Giraffe Academy"; $phrase[0] = "B"; echo $phrase;
Print out the variable as "Biraffe Academy" | It changes the character in position 0 "G" to "B"
32
How to replace a part of a string? Command and example?
``` str_replace if $phrase ="Giraffe Academy"; echo str_replace ("Giraffe", "Panda", $phrase); ```
33
Another str_replace example?
``` if $phrase ="Cat Fish"; echo str_replace ("Cat", "Dog", $phrase); would print out Dog Fish ```
34
what does substr do?
The substr() function is used to cut a part of a string from a string, starting at a specified position.
35
``` What would this do? $phrase = "Giraffe Academy"; echo substr ($string, 8); ```
It would grab the string values starting a index position 8 and print it - in this case Academy
36
``` What would this do? $phrase = "Giraffe Academy"; echo substr ($string, 8, 3); ```
It would grab the string values starting a index position 8 and print it to 3 positions out - in this case in would print Aca
37
Output | 3
38
Example
Output | Welcome to the programming world
39
How to print a number?
echo 40; | prints out 40
40
What would this print?
echo 5 + 9; prints 14
41
What does this do? | echo 10 % 3;
Prints the modulus so, 10 /3 is 3, with a remainder of 1 | Prints 1
42
echo 4 + 5 * 3;
gives us 19
43
but echo (4 + 5) * 3;
gives us 27 - PEMDAS order matters