25.09.2014 Views

ZEND PHP 5 Certification STUDY GUIDE

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

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

38 ” Functions<br />

{<br />

}<br />

echo "Hello World!";<br />

hello(); // Displays "Hello World!"<br />

Returning Values<br />

All functions in <strong>PHP</strong> return a value—even if you don’t explicitly cause them to. Thus,<br />

the concept of “void” functions does not really apply to <strong>PHP</strong>. You can specify the<br />

return value of your function by using the return keyword:<br />

function hello()<br />

{<br />

return "Hello World"; // No output is shown<br />

}<br />

$txt = hello(); // Assigns the return value "Hello World" to $txt<br />

echo hello(); // Displays "Hello World"<br />

Naturally, return also allows you to interrupt the execution of a function and exit it<br />

even if you don’t want to return a value:<br />

function hello($who)<br />

{<br />

echo "Hello $who";<br />

if ($who == "World") {<br />

return; // Nothing else in the function will be processed<br />

}<br />

Licensed to 482634 - Amber Barrow (itsadmin@deakin.edu.au)<br />

}<br />

echo ", how are you";<br />

hello("World"); // Displays "Hello World"<br />

hello("Reader") // Displays "Hello Reader, how are you?"

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

Saved successfully!

Ooh no, something went wrong!