Start with the basic PHP page again, and save your work as variables2.php:
<html>
<head>
<title>More on Variables</title>
</head>
<body>
<head>
<title>More on Variables</title>
</head>
<body>
<?php
print ("Basic Page");
?>
</body>
</html>
</html>
We'll now set up a variable and print it to the page. So change your code to this:
<?php
$first_number = 10;
print ($first_number);
print ($first_number);
?>
All the code does is to print the contents of the variable that we've called $first_number. Remember: if you're printing direct text then you need quotation marks; if you're printing a variable name then you leave the quotes out. To see why, run the first script above. Then change the print line to this:
print ("$first_number");
In other words, add double quotation marks around your variable name. Did it make a difference? What did you expect would print out? Now change the double quotes to single quotes. Run your script again. With double quotes, the number 10 still prints; with single quotes, you get the variable name!
No comments:
Post a Comment