More PHP Variable Practice
You outputted text to a page. In the next few sections, you’ll do some more work with variables, and learn how to do your sums with PHP.
But now that you can print text to a page, let’s try some numbers. Start with the basic PHP page again, and save your work as variables2.php:
<html> <head> <title>More on Variables</title> </head> <body> <?php print ("Basic Page"); ?> </body> </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); ?>
All the code does is to print the contents of the variable that we’ve called:
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: