ch3 questions Flashcards
What tag is used to cause PHP to start interpreting program code? And what is the short form of the tag?
<?
the short form is deprecated
What are the two types of comment tags?
// single line comment /* multiline comment */
Which character must be placed at the end of every PHP statement?
;
Which symbol is used to preface all PHP variables?
$
What can a variable store?
numbers, strings, arrays
What is the difference between $variable = 1 and $variable == 1?
$variable = 1 declares $variable as 1
$variable == 1 compares $variable to 1
Why do you suppose an underscore is allowed in variable names (e.g., $current_user) whereas hyphens are not (e.g., $current-user)?
Because the hyphen ( - ) is also a subtraction operator
Are variable names case-sensitive?
Yes
Can you use spaces in variable names?
No
How do you convert one variable type to another (say, a string to a number)?
To convert a variable type to another, reference it and PHP will automatically convert it for you.
What is the difference between ++$j and $j++?
++$j increment before
$j++ increment after
Are the operators && and ‘and’ interchangeable?
Yes but && has higher precedence than and
How can you create a multiline echo or assignment?
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)
Can you redefine a constant?
No
How do you escape a quotation mark?
By prefacing it with \
What is the difference between echo and print commands?
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.
What is the purpose of functions?
Functions are used to separate out sections of code that perform a particular task and make it easier to execute that task repeatedly.
How can you make a variable accessible to all parts of a PHP program?
By making the variable a global variable. Using the syntax:
global $variable;
If you generate data within a function, what are a couple of ways to convey the data to the rest of the program?
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.
What is the result of combining a string with a number?
The number becomes part of the string