ch3 questions Flashcards

1
Q

What tag is used to cause PHP to start interpreting program code? And what is the short form of the tag?

A

<?

the short form is deprecated

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

What are the two types of comment tags?

A
// single line comment
/* multiline
 comment */
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which character must be placed at the end of every PHP statement?

A

;

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

Which symbol is used to preface all PHP variables?

A

$

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

What can a variable store?

A

numbers, strings, arrays

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

What is the difference between $variable = 1 and $variable == 1?

A

$variable = 1 declares $variable as 1

$variable == 1 compares $variable to 1

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

Why do you suppose an underscore is allowed in variable names (e.g., $current_user) whereas hyphens are not (e.g., $current-user)?

A

Because the hyphen ( - ) is also a subtraction operator

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

Are variable names case-sensitive?

A

Yes

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

Can you use spaces in variable names?

A

No

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

How do you convert one variable type to another (say, a string to a number)?

A

To convert a variable type to another, reference it and PHP will automatically convert it for you.

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

What is the difference between ++$j and $j++?

A

++$j increment before

$j++ increment after

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

Are the operators && and ‘and’ interchangeable?

A

Yes but && has higher precedence than and

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

How can you create a multiline echo or assignment?

A
Using heredoc tags or quotation marks
<<<_TAGNAME
multiline
echo
_TAGNAME;
(the closing tag should be at the beginning of a line and followed by a semicolon, nothing else can be on the line)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Can you redefine a constant?

A

No

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

How do you escape a quotation mark?

A

By prefacing it with \

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

What is the difference between echo and print commands?

A

The echo and print commands are similar in that they are both constructs, except that print behaves like a PHP function and takes a single argument, while echo can take multiple arguments.

17
Q

What is the purpose of functions?

A

Functions are used to separate out sections of code that perform a particular task and make it easier to execute that task repeatedly.

18
Q

How can you make a variable accessible to all parts of a PHP program?

A

By making the variable a global variable. Using the syntax:

global $variable;

19
Q

If you generate data within a function, what are a couple of ways to convey the data to the rest of the program?

A

If you generate data within a function, you can convey the data to the rest of the program by returning a value or modifying a global variable.

20
Q

What is the result of combining a string with a number?

A

The number becomes part of the string