Have an account? Sign in
Login  Register  Facebook
This Page is Under Construction! - If You Want To Help Please Send your CV - Advanced Web Core (BETA)
Quick Table of Contents
  • print() — statement outputs data passed to it
  • echo() — statement for the same purposes as print()
  • printf() — output a blend of static text and dynamic information
  • sprintf() — identical to printf() except that the output is assigned to a string
[Edit] The echo() Statement
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])
To use echo(), just provide it with an argument just as was done with print():
echo "I love the summertime.";
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:
<?php
$he = "Brad";
$she = "Angelina";
echo $he, " and ", $she, " are great couple.";
?>
This code produces the following:
Brad and Angelina are great couple.
Executing the following (in my mind, more concise) variation of the above syntax produces the same output:
echo "$he and $she are great couple.";
If you hail from a programming background using the C language, you might prefer using the printf() statement, introduced next, when outputting a blend of static text and dynamic information. Tip Which is faster, echo() or print()? The fact that they are functionally interchangeable leaves many pondering this question. The answer is that the echo() function is a tad faster because it returns nothing, whereas print() will return 1 if the statement is successfully output. It’s rather unlikely that you’ll notice any speed difference, however, so you can consider the usage decision to be one of stylistic concern.
September 12, 2011