Assigning Values to Variables

When you declare a variable, you assign a value to it:

$var_name = value;

To access the value of a variable that's already been assigned, simply specify the dolalr sign ($) followed by the variable name, and use it as you would the value of the variable in your code.

You don't have to clean up your varaibles when your program finishes. They're temporary because PHP automatically cleans them up when you're done using them.

<html>
<head>
<title>PHP</title>
<meta Name="Author" Content="Hann So">
</head>
<body>
<p>
<?php
$hello = "Hello World!";
$year = 2008;
echo $hello;
echo $year;
?>
</p>
</body>
</html>

View the effect


Variables | Identifiers | What are Variables? | Assigning Values to Variables | Data Types | Variable Scope | Interpolating Variables in Strings | Creating Variables Variables | Creating Constants
© 2008: Hann So
email: hso@voyager.deanza.edu