Chapter 3 Answers
The tag used to start PHP interpreting code is
<?php ... ?>, which can be shortened to<? ... ?>.You can use
//for a single-line comment or/* ... */to span multiple lines.All PHP statements must end with a semicolon (
;).With the exception of constants, all PHP variables must begin with
$.A variable holds a value that can be a string, a number, or other data.
$variable = 1is an assignment statement, whereas$variable == 1is a comparison operator. Use$variable = 1to set the value of$variable. Use$variable == 1to find out later in the program whether$variableequals1. If you mistakenly use$variable = 1where you meant to do a comparison, it will do two things you probably don’t want: set$variableto1and return atruevalue all the time, no matter what its previous value was.A hyphen is reserved for the subtraction operators. A construct like
$current-userwould be harder to interpret if hyphens were also allowed in variable names and, in any case, would lead programs to be ambiguous.Variable names are case-sensitive.
$This_Variableis not the same as$this_variable.You cannot use spaces in variable names, as this would confuse the PHP parser. Instead, try using the
_(underscore).To convert one variable type to another, reference it and PHP will automatically convert it for you.
There is no difference between
++$jand$j++unless the value of$jis being tested, assigned to another variable, or passed as a parameter to a function. In such cases,++$j ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access