Variables

Creator:
Tripper

For this tutorial it is reccomended you have access to a PHP host or server, if you wish to try any of the examples.


Variables hold data, thats all. They are not an impressive function, or nor do they require excellent PHP skills they are there to hold data you may need again. For example,



 <? echo 'Hello Woody'
echo 
'Howdy Woody'
echo 
'Was up Woody?'
echo 
'l8r Woody'?>

We could create a variable, to replace Woody. Here is an example of a variable

$who = 'Woody';

The $who is the name of the Variable, by using $ PHP knows we are creating a Variable, the = sign is what the Variable contains, and between the ' are the Variable contents, Simple?

If we want to echo our welcomes to Woody we could use

echo $woody;

Here is a full example



 <? 
    $who 
'Woody'
    echo 
'Hello '.$who.''
    echo 
'Howdy '.$who.''
    echo 
'Was up '.$who.''
    echo 
'l8r '.$who.''
?>

Instead of echoing Woody out, we are now echoing $who out, so if you want Woody could become Woodette or Woot just by changing the Variable content, instead of replacing every Woody we wrote.

Now you should have an understanding of how to create a Variable, and how to echo them.

Description:
This Tutorial will attempt to teach you how to use Variables.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options