Midterm Study Flashcards

1
Q

What does PHP stand for?

A

Php hypertext protocol

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

Is php statically or dynamically typed?

A

Php is dynamically types because any variable can contain any value

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

Is php strongly or weakly typed,

A

Php is weakly typed because a value of any type can be used in expressions. Eg. 78 > “PHP” does not cause an error, first it tries to convert the string into a number, of it can’t then the string gets a value of 0 and then it is compared.

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

What type of language is PHP?

A

Php is an imperative server side scripting language. This means that the code runs on the server not on the client, the scripts are run and the results are sent to the client. Being imperative means php does not need a main class to function, it can stand alone and gets executed sequentially.

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

What does imperative mean?

A

Imperative means that the language does not need a main method to run, it can stand alone, be embedded and gets executed in a sequential order

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

Can you see PHP in the browsers inspection tool?

A

No PhP is server side and is not accessible by the client.

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

When do you need to add .php to the end of your file?

A

When there is any php whatsoever in the file.

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

What is the difference between single and double quotes in php?

A

Single quotes are literal strings where double quotes are executed, if you have a variable in doh or quotes it will call the variable, single quotes will not

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

How do you create a function in PHP?

A

Function functionName ($a, $b) { code; }

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

Is PHP interpreted or compiled?

A

Interpreted in real time in the browser

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

What is the symbol used for concatenation in PHP?

A

. Not +

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

Reserved words, functions, and class names are; case sensitive or case insensitive?

A

Case insensitive, but variable names are case sensitive

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

What is an associative array in PHP?

A

Like a dictionary in python, it is an array of key and value pairs.

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

What are the two syntactically correct ways to create associative arrays?

A
$user = [];
$user[“studentid”] = “9265743”;
$user[“age”] = 22;

OR

$user = [“studentid”=>”9036538”, “age”=>”22”];

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

What are the 3 syntactically correct ways to echo associative arrays?

A

echo “Your Userid: {$user[“studentid”]}”;

echo “Your Userid: $user[studentid]”;

echo “Your Userid: {$user[$a.$b]}”;

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

How would you loop through an associative array?

A

foreach ($user as $key => $value) {
echo “$key$value”;
}

17
Q

What are the two symbols used most often in the get parameter?

A

? for the start of the list, and the and symbol separating items if there are more than one.

18
Q

How does a form look like when using get or post methods?

A

First Name: <br></br>

Last Name: <br></br>

19
Q

How do you use the get method to get the input from the form?

A

echo “<p>Hello, Mr. {$_GET[“lastName”]}. May I call you {$_GET[“firstName”]}?</p>”;

Making sure that the items in the get methods are the names from the input items on the form.

20
Q

What is the difference between the get and post methods?

A

If you use method=”POST”, you will not see the parameters in the browser because they are sent in the body of the HTTP Request message rather than in the header as part of the URL.
POST is better than GET for sensitive information like passwords or credit card numbers. But POST is not really secure!

21
Q

What does the count function do?

A

The count function can be used to tell you how many items are stored in an associative array. So if count($_GET)is 0, then you didn’t receive any GET parameter

22
Q

What does the isset function do?

A

The isset function can be used to test if variable names or array indices have been given values. For example if isset($_POST[‘userid’])returns false, then you didn’t receive a post parameter named ‘userid’

23
Q

What does the strlen function do?

A

The strlen function can be used to find out whether a string is empty or not (i.e. if it returns 0, the string is empty)

24
Q

What does the is_numeric function do?

A

The is_numeric function can be used to test if a parameter can be interpreted as a number

25
Q

How does the empty function work?

A

This function returns true if an array or string is empty. So if empty($_GET) is true, you received no GET parameters and if empty($_GET[‘userid’]) is true you got an empty string for the userid parameter.

26
Q

How do you redirect a form back to itself?

A

A page can redirect back to itself by using the following code for the action attribute of the element:
action=”= $_SERVER[‘PHP_SELF’]?>”

27
Q

How would you print the name column from every row retrieved?

A
$names = [];
while ($row = $stmt->fetch())
{ array_push($names, $row['name']); }
echo "";
for ($i = 0; $i < count($names); $i++) {
echo "$names[$i];
} echo "";