Follow this lesson in Ullman Chapter 2. The scripts are located in the 02 directory.
http://us2.php.net/manual/en/language.variables.predefined.php
Using print_r()
Using <pre>
$GLOBALS
View the page print_r.php described in Ullman pp. 26 ff.
Note the Ullman section on Predefined Variables on page 26.
Printing your $GLOBALS value is valuable for debugging.
<pre>
<?php
print_r ($GLOBALS);
?>
</pre>
$variablename
The $ must come first.
Variable names can start with a letter or an underscore: _
Variable names cannot start with a number or other character.
Variable names are case-sensitive.
But you need not declare a variable before using it!
“under_score” vs. “camelHump” methods.
Numbers
Integer
Floating-point
String
Boolean
There is no “date” variable type in PHP.
Numerically indexed (indexed arrays)
Keyword-indexed (associative arrays)
Multidimensional arrays
See Ullman page 35 for two examples of arrays.
= the assignment operator
View the page variables.php described on pp. 38-39 of Ullman.
” ” – weak quotes
The purpose of weak quotes is to preserve empty spaces.
‘ ‘ – strong quotes (literal quotes)
The purpose of strong quotes is to allow you to pass literal strings. Variables etc. will NOT be interpreted.
See the page quotes.php described on pp 40-41 of Ullman.
Create your own demonstration page for these techniques:
- printing your GLOBALS array;
- creating and assigning variables;
- displaying variables; and
- demonstrating the effects of weak and strong quotes.
Be sure to link this page to your index.htm.
As a test to see if you’re reading these instructions, I’m going to check that you have substituted your name for Ullman’s! (Just kidding.)
Review Chapter 2 of Ullman.