Workshop

The workshop is designed to help you anticipate possible questions, review what you've learned, and begin putting your knowledge into practice.

Quiz

1:

Which of the following variable names is not valid?

 $a_value_submitted_by_a_user $666666xyz $xyz666666 $___counter___ $the first $file-name 
A1:

The variable name $666666xyz is not valid because it does not begin with a letter or an underscore character. The variable name $the first is not valid because it contains a space. $file-name is also invalid because it contains a nonalphanumeric character.

2:

What will the following code fragment output?

 $num = 33; (boolean) $num; print $num; 
A2:

The fragment will print the integer 33. The cast to Boolean produces a converted copy of the value stored in $num. It does not alter the value actually stored there.

3:

What will the following statement output?

 print gettype("4"); 
A3:

The statement will output the string "string".

4:

What will be the output from the following code fragment?

 $test_val = 5.5466; settype( $test_val, "integer" ); print $test_val; 
A4:

The code will output the value 5. When a double is converted to an integer, any information beyond the decimal point is lost.

5:

Which of the following statements does not contain an expression?

 4; gettype(44); 5/12; 
A5:

They are all expressions because they all resolve to values.

6:

Which of the statements in question 5 contains an operator?

A6:

The statement 5/12; contains a division operator.

7:

What value will the following expression return?

 5 < 2 

What data type will the returned value be?

A7:

The expression will resolve to false, which is a Boolean value.

Activities

  1. Create a script that contains at least five different variables. Populate them with values of different data types and use the gettype() function to print each type to the browser.

  2. Assign values to two variables. Use comparison operators to test whether the first value is

    • The same as the second

    • Less than the second

    • Greater than the second

    • Less than or equal to the second

    Print the result of each test to the browser.

    Change the values assigned to your test variables and run the script again.



Sams Teach Yourself PHP, MySQL and Apache in 24 Hours
Sams Teach Yourself PHP, MySQL and Apache in 24 Hours
ISBN: 067232489X
EAN: 2147483647
Year: 2005
Pages: 263

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net