Make sure to end your line of PHP code with a semicolon.
A string is a word or phrase between quotes, like so: "Hello, world!"
You can type a string all at once, like this:
<?php
echo "Hello, world!";
?>
Or use the concatenation operator, which glues several strings together:
<?php
echo "Hello," . " " . "world" . "!";
?>
The concatenation operator is just a dot (.). (If you're coming to PHP from JavaScript, the dot does the same thing for strings that +does in JavaScript.)
So far we've been outputting strings and doing math.
To do more complex coding, we need a way to "save" these values. We can do this usingvariables. A variable can store a string or a number, and gives it a specific case-senstive name.
Examples:
$myName = "Beyonce";
$myAge = 32;
All variable names in PHP start with a dollar sign ( $ ).
You've probably noticed that our lines of PHP code end in semicolons (). PHP requires semicolons at the end of eachstatement, which is the shortest unit of standalone code. (For example, echo"Hello!"; or 2 + 2;)
You can think of a statement is a complete PHP thought. 19 + or echo aren't complete thoughts, so you wouldn't put semicolons at the end of them!
<?php echo "Use your semicolons!"; ?>
- Follow Us on Twitter!
- "Join Us on Facebook!
- RSS
Contact