In order to become familiar with PHP programming structures and commands, we will build various PHP pages. Sections of this page will explain each PHP command, provide a link to a working sample, and detail the working sample's PHP code. Let's get started:
| Variables |
|---|
$student="Julio Garcia"; I can then tell PHP to print($student); and PHP will print: Julio Garcia. print($student); For example: variables.php |
<html>
<head>
<title>variables.php</title>
</head>
<body>
<?php
$student="Julio Garcia";
Print($student);
?>
</body>
</html>
You can also do the following:
$number1=10;For example:variables2.php
<html>
<head>
<title>variables.php</title>
</head>
<body>
<?php
$number1=10;
$number2=15;
$number3=5;
$total=$number1+$number2+$number3;
print("<p>The sum of the numbers is ".$total."</p>");
print("I have ".($number1+$number2+$number3)." dollars!");
?>
</body>
</html>
In JavaScript, we used var student to declare the variable. We then set a value to the variable by using student = "Julio Garcia".