11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 4 • FUNCTIONSwww.it-ebooks.infoIf you want to output the function outcome within a larger string, you need to concatenate it like this:echo "Five raised to the third power equals ".pow(5,3).".";Or perhaps more eloquently, you could use printf():printf("Five raised to the third power equals %d.", pow(5,3));In the latter two examples, the following output is returned:Five raised to the third power equals 125.■ Tip You can browse <strong>PHP</strong>’s massive function list by visiting the official <strong>PHP</strong> site at www.php.<strong>net</strong> and perusing thedocumentation. There you’ll find not only definitions and examples for each function broken down by library, butreader comments pertinent to their usage. If you know the function name beforehand, you can go directly to thefunction’s page by appending the function name onto the end of the URL. For example, if you want to learn moreabout the pow() function, go to www.php.<strong>net</strong>/pow.Creating a FunctionAlthough <strong>PHP</strong>’s vast assortment of function libraries is a tremendous benefit to anybody seeking toavoid reinventing the programmatic wheel, sooner or later you’ll need to go beyond what is offered inthe standard distribution, which means you’ll need to create custom functions or even entire functionlibraries. To do so, you’ll need to define a function using <strong>PHP</strong>’s supported syntax, which when written inpseudocode looks like this:function functionName(parameters){function-body}For example, consider the following function, generateFooter(), which outputs a page footer:function generateFooter(){echo "Copyright 2010 W. Jason Gilmore";}Once defined, you can call this function like so:92

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

Saved successfully!

Ooh no, something went wrong!