php print statement

The print() statement outputs data passed to it to the browser.Its prototype looks like this:

print - syntax

int print ( argument )

All of the following are plausible print() statements:

print - example 1

print("<p>I love the summertime.</p>");

print - example 2

$season = "summertime";
print "<p>I love the $season.</p>";

print - example 3

print "<p>I love the summertime.</p>";

output :

All these statements produce identical output:

I love the summertime.

Note : Although the official syntax calls for the use of parentheses to enclose the argument, they're not required. Many programmers tend to forgo them simply because the target argument is equally apparent without them.

Alternatively, you could use the echo() statement for the same purposes as print().While there are technical differences between echo() and print(), they'll be irrelevant to most readers and therefore aren't discussed here. echo()'s prototype looks like this:

void echo(string argument1 [, ...string argumentN])

As you can see from the prototype, echo() is capable of outputting multiple strings. The utility of this particular trait is questionable; using it seems to be a matter of preference more than anything else. Nonetheless, it's available should you feel the need. Here's an example:

print - example 4

$heavyweight = "Lennox Lewis";
$lightweight = "Floyd Mayweather";
echo $heavyweight, " and ", $lightweight, " are great fighters.";

This code produces the following:

Output :

Lennox Lewis and Floyd Mayweather are great fighters.

If your intent is to output a blend of static text and dynamic information passed through variables, consider using printf() instead, which is introduced next. Otherwise, if you'd like to simply output static text, echo() or print() works great.