Friday, 28 August 2009

Php Tutorial Part 2

Variables: Variables are very usefull part of a programming language. They can store temporary information for useful functions like calculations.
Remember that the code must be surounded by: variables must have $ (dollar) at the beginning of the variable

$var1 = "Stavros";
echo $var1;
?>
This code will output to the user "Stavros".
variables as I said above are very useful and because php is a loosely Typed Language you don't have to tell to the php engine what type of data you will save in the variable, php engine will work out what type of data you have save. In php you don't have to initialise your variables.


$a = 1;
$b = 4;
$c = $a + b;
echo $c;
?>
The output of the above code is: 5
More about variables:
They have restrictions and you can get very strange messages if you do not follow the rules for declaring them.
Variables must begin with $ followed by letter or _ (underscore) They cannot start with number like $1test this is wrong and you will get error.
Variables can contain numbers like $test1. You cannot have variables that have space inside php will return error, if you have a big word for variable do it like this $colour_of_dog or $ColourOfDog Both are correct.
To set a value to a variable use = NOT == because it means equal with something
Tip: to create good websites you need to know HTML, most websites are combination of html and php, you will use php without html tags only for calculations, validating users etc...

No comments:

Post a Comment

Reset numbering for Screenshots Win+PrtSc

I was using today the screen shot functionality of Windows 8.1 Win Key + PrtSc How to reset the numbering?