<?php echo “I am Apollo”; '<br>' echo “I am Apollo”; ?>
All I would have to type in is the variable. It can make writing php a whole lot neater and let you repeat certain words without having to type it ALL in again or copy and paste it. So, to begin we will start with a name variable.
<?php $name = “Apollo”; echo “I am $name”; '<br>' echo “I am $name”; ?>
Now save it as “Tutorial 2 – Variables.php” and save it to “(drive letter where you installed xampp):\xampp\htdocs\tutorials”. Make sure xampp is open and apache and MySQL are running. Go to your web browser and type: localhost:2375/tutorials or localhost:80/tutorials depending on which you have and press enter.
Click “Tutorial 2 – Variables.php” and you see… It should project “I am Apollo” two times.
So, you see instead of typing “I am Apollo” as the echo I typed “I am $name” now if I wanted to say: “I am Apollo and I am (blank) years old” then I would have to create a new variable called a number variable. To do a number variable all you have to do is:
<?php $name = “Apollo”; $age = 20; echo “I am $name and I am $age years old”; ?>
See the difference? The difference is that the name variable has “” around the variable. But the number variable doesn’t.. If you were to type:
$age = two;
It would not work because it is a NUMBER but it isn’t the actual symbol type number (1, 2, 3, 4, 5, etc..)
There are other types of variables that you can use to called POST and GET but we will get into thoughs later because that includes html coding to..
That is the end of this tutorial. If you would like to go more in depth with variables sooner rather than later, P.M me. The next tutorial should be out in a few days.
Edited by {IP}Apollo, 09 April 2012 - 08:16 PM.