The Tutorial-Wizards Easiest Tutorials On The Web

PHP – Setting Basic Variables

Author: Martin9t9

Aim: To get a good understanding of how to use variables in PHP.

Requirements: A server that supports PHP - Notepad

Howto:

  1. The first thing you guys should know is that PHP is a server side computer language and will only work on a server and will not compile on your computer. And secondly, the file must have a .php file extension. eg. variables.php
  2. Alright, I want you to imagine a variable as a person that remembers a value for you so you dont have to do it.
  3. To start a PHP script you must put everything between:
    <?PHP

    ?>

  4. Ok now to the fun stuff. We want our really smart person to remember the number '25' but we want this person to remember it as $first_variable. So pretty much we're saying $first_variable = 25 just to make it easier later on.
    Eg.

    <?PHP

    $first_variable = 25

    ?>

  5. Now lets add another variable:

    <?PHP

    $first_variable = 25;

    $second_variable = 15;

    ?>

    Now lets add them two variables together and display it on your screen:

    <?PHP

    $first_variable = 25;
    $second_variable = 15;

    print($first_variable + $second_variable);

    ?>
    This adds 25 to 15.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

Trackbacks are disabled.