Review Exercises

What is the significance of a form’s method attribute? Of its action attribute?

Form's "method" attribute dictates how the data is sent to the handling page GET is used for requesting information. POST is used when an action is expected

Why must an HTML form that gets submitted to a PHP script be loadedthrough a URL? What would happen upon submitting the form if it were not loaded through a URL?

I am not sure. I think client requests server through a URL.

I'm not sure.If it weren't loaded through a URL, Nothing will happen.

What are the differences between using single and double quotation marks to delineate strings?

Single quotes for not interpreting, double quote for interpreting.

What control structures were introduced in this chapter?

If(condition1){} elseif(codintion2){} else{}

switch($variable){case 'value1':break; case 'value2': break; default:break;}

What new variable type was introduced in this chapter?


What operator tests for equality? What is the assignment operator?

double equals sign (= =) means equals, a single equals sign (=) assigns a value

Why are textual form elements validated using empty( ) but other form elements are validated using isset( )?

isset() to check if the variable has a value other than NULL; 0,FALSE, empty string. an empty string tests as true. not an effective way to validate text inputs & text boxes from an HTMl form.

empty() to check whether a variable is considered to be empty: NULL, empty string, 0,0.0,"0",FALSE, array()-empty array,$var; (a variable declared, but without a value)

To check that a user typed something into textual elements, you can use empty()function

What is the difference between an indexed array and an associative array?

indexed array use numbers as the keys; start with 0 unless define it. $artists[0];

associative array use strings as keys. $states['MD'];

With what value do indexed arrays begin (by default)? If an indexed array has ten elements in it, what would the expected index be of the last element in the array?

By default, indexed arrays begin at 0

last element's index is 9

What are the superglobal arrays? From where do the following superglobals get their values? > $_GET > $_POST> $_COOKIE> $_REQUEST> $_SESSION> $_SERVER> $_ENV

Superglobal arrays are predefined arrays which are included in PHP

$_GET is where PHP stores all the values sent to a PHP script via the GET method.

$_POST stores all data sent to a PHP script form an HTML form that uses the POST method

$_REQUEST to access form data submitted through the POST method, $POST would be more accurate.

$_COOKIE are subsets of $_REQUEST> more info in chp 12

$_SESSION > in chp 12

$_ENV > in chp 12

$_SERVER refers to a mass of server-related information.

How can you print an individual indexed array item? How can you print an individual associative array item? Note: there is more than one answer to both questions.

print $artists[0]; print $states['MD'];

What does the count( ) function do?

To determine the number of elements in an array, use count(): eg.,$num = count($array);

What impact does printing \n have on the Web browser?

new line

Generally speaking, when would you use a while loop? When would you use a for loop? When would you use a foreach loop? What is the syntax of each loop type?

1. While loop wil most frequently be used when retrieving results from a database. as long as the condition part of the loop is true, the loop will be executed. Once it becomes false, the loop is stopped.if the condition is never true, the loop will never be executed
while (codintion){ //Do something } "while loop" is doing something an unknown number of times

2. For loop > for loop is doing something a known number of times; it executes at least one time.Upon first executing the loop, the initial expression is run . Then the condtion is checked and if true, the contents of the looop are execute.
for (initial exp;condition;closing exp){//do something;}

3. Foreach loop> To access every element in array, use the foreach loop. foreach($array as $value){ //Do something with $value }
to access both thekeys and values foreach ($array as $key => $value){ echo "the value at $key is $value";}

What is the ++ operator? What does it do?