Information Anime&Manga Programming Design
eXTReMe Tracker

Simple Numeric Variables

This lesson will show extremely easy to manipulate variables in PHP, just change them and experiment in order to gain a desired effect.

55 + 65/100 = 20

<?php
// Beginning of PHP Script

$fifty_five = 55;
$sixty_five = 65;
$one_hundred = 100;
$answer = 20;

$statement = "$fifty_five + $sixty_five/$one_hundred = $answer";

echo $statement;

// End of PHP Script
?>

This tutorial is showing you how to manipulate and create various variables, especially numeric variables in this example. As in any PHP script, always start off with "<?php" and always end with "?>". The labels within the script are called single line comments and are used to display basic information regarding scripts and parts of a script.

As for the actual variables, here goes...the first one you see if "$fifty_five = 55;", all variables can be written with any combination of lower case or upper case characters, as well as the underscore but you may not use a dash or a space between variables (as they will not function with a space or other characters at this time). The rest of the variables are just used for storing numeric data. Notice that I set each variable to match each number. The "$statement = "$fifty_five + $sixty_five/$one_hundred = $answer" line is the core of this script. What that does is add the fifty_six variable to the sixty_five variable, divided by the one_hundred variable and that equals the "$answer" (variable displaying the answer). The echo function writes text to a web browser, so you get the statement of variables wrote to whatever browser you are using at the time. In short, variables are used for storing data and I've given you an example of how they may be used. There's no limit to what you can create, except for your own creativity, enjoy!