Privacy Policy

Community
Standards


Youth Tech's Online PHP Class: Lesson Two

Variables and More Output [Chat: 7/19/02]

Hosted by YTCC Spark

Welcome back to PHP Class!  I hope you all found Lesson One informative.  If you have any questions, as always, don't hesitate to email me.  Or, the preferred method, bring your questions to Chat, 10PM EST, every Friday!

Variables

Think of variables like your memory.  Without it, your brain wouldn't do a whole lot.  Variables are where a program stores things while it works with them.

In PHP, all variables are named and begin with a $.  They then contain any combination of letters, numbers, and underscores(_).  They should only begin with a letter (after the $).

Acceptable variables: $name, $order_no, $country, $address, $phone_number, $abc_123.

Important NOTE: Variables are case-sensitive.  That is, $PIZZA, $Pizza, and $pizza are all different variables.  I do not suggest using variations on the same name with only different cases.  It's too easy to get confused.  It's better to use $pepperoni_pizza and $cheese_pizza.

Assigning Values to Variables

$name = "YTCC Spark";

$age = 17;

$country = "USA";

$my_age = $age;

$area = $length * $width;

Printing Variables

echo "My name is: ", $name, "\n";

print "My name is: $name";

Both code snippets have the same effect.

print "I am $age years young.";

Print can also be used in the following way if it makes it easier for you to read.

print ("I am $age years young.");

There are no differences in the output or how it works.  It is just a matter of style/preference.

See sample code for lesson two.
See the code in action.

Back to the Index

 

Copyright © 1996-2003, Youth Tech
Questions? Comments?