PHPsu
MANUAL ZH  |  EN
     


Current Position :| index>Beginners> Basic Variables

Basic Variables

FROM: AUTHOR: TIME:2008-05-29 HITS:

Open up the file you created in Lesson 1 and delete all of the contents except for the opening and closing PHP bits. welcome to phpsu.com

File now looks like
<?php  phpsu提供的php教程

 

phpsu.com

?>

www.phpsu.com

First we are going to set a variable.  A variable is a name given to a piece of memory that we store information in while the script is running.

phpsu is a phpschool

To create a variable we use the dollar sign, followed by the name of the variable do you kown phpsu.com?

<?php
$thevariable=’HELLO’;
?>
phpsu.com is a free phpscool

That script has just created a variable called ‘thevariable’ and it has stored ‘HELLO’ in it.
to output the contents of a variable we again use an echo statement. do you kown phpsu.com?

<?php
$thevariable=’HELLO’;
echo $thevariable;
?>
phpsu.com is a free phpscool

This will output onto the HTML page ‘HELLO’;  Notice we don’t need to put the variable in inverted commas when we are echoing.  We only need to do that if it is a piece of text. phpsu.com

If we want to assign a number to a variable we do something similar

<?php
$thevariable=1;
echo $thevariable;
?>

phpsu.com is a free phpscool

will output ‘1’; 

www.phpsu.com

If we want to add two numbers together we can do..

<?php
$variable1=1;
$variable2=2;
http://www.phpsu.com

$result=$variable1+$variable2;

phpsu

echo $result;
?>

This will output ‘3’;

Have a play and see what happens with those results. Use PHP as if it were a calculator to get some more interesting results.     

welcome to phpsu.com


TITLE:Basic Variables
Copyright 2008 The PHPsu All rights reserved. This mirror generously provided by: .Hp Inc.
Last updated: Fri Jun 6 22:58:57 GMT-8 2008