Monday, September 27, 2010

The print() Function

print() is a function that outputs data. In most cases, anything output by print()
ends up in the browser window. A function is a command that performs an action,
usually modified in some way by data provided for it. Data sent to a function is
almost always placed in parentheses after the function name. In this case, you sent
the print() function a collection of characters, or string. Strings must always be
enclosed by quotation marks, either single or double.

Note: Function calls generally require parentheses after their name whether or
not they demand that data be passed to them. print() is an exception,
and enclosing the data you want to print to the browser in parentheses is
optional. This is the more common syntax, so we will usually omit the
brackets in our examples.
You ended your only line of code in Listing 3.1 with a semicolon. The semicolon
informs the interpreter that you have completed a statement.

NEW TERM
A statement represents an instruction to the interpreter. Broadly, it
is to PHP what a sentence is to written or spoken English. A
statement should usually end with a semicolon; a sentence should
end with a period. Exceptions to this include statements that
enclose other statements, and statements that end a block of code.
In most cases, however, failure to end a statement with a semicolon
will confuse the interpreter and result in an error.
Because the statement in Listing 3.1 is the final one in that block of code, the
semicolon is optional.

No comments:

Post a Comment