11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.it-ebooks.infoCHAPTER 3 • <strong>PHP</strong> BASICSThe echo() StatementAlternatively, you could use the echo() statement for the same purposes as print(). While there aretechnical differences between echo() and print(), they’ll be irrelevant to most readers and thereforearen’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 ofthis particular trait is questionable; using it seems to be a matter of preference more than anything else.No<strong>net</strong>heless, it’s available should you feel the need. Here’s an example:This code produces the following:Lennox Lewis and Floyd Mayweather are great fighters.Executing the following (in my mind, more concise) variation of the above syntax produces thesame output:echo "$heavyweight and $lightweight are great fighters.";If you hail from a programming background using the C language, you might prefer using theprintf() 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 manypondering this question. The answer is that the echo() function is a tad faster because it returns nothing, whereasprint() will return 1 if the statement is successfully output. It’s rather unlikely that you’ll notice any speeddifference, however, so you can consider the usage decision to be one of stylistic concern.The printf() StatementThe printf() statement is ideal when you want to output a blend of static text and dynamic informationstored within one or several variables. It’s ideal for two reasons. First, it neatly separates the static anddynamic data into two distinct sections, allowing for easy maintenance. Second, printf() allows you to47

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!