Php Functions are nice building blocks for your scripts to store needed processes or code to be used only as need by calling them into other scripts or files to run. They have the ability to pass variables by taking in the variable, doing something with it and then spitting it out as a finished process within your scripts see demos below:

function myFunction()
echo 'Hello World';
}//end myFunction
function myInfo()
echo 'Mr.Fred Flinstone 4213 Rock Ridge Road zip:000024';
$myvar='capitalize the first word in this string.';
function doVars($newvar)//converts $myvar to $newvar inside the function//
$caps= ucfirst($newvar);
echo $caps;
//execute both functions on same page or use include('path/function_file.php')on top of
//--the page where needed to call the functions//
//to execute
echo'<br />';
echo'<br />';
//lets do one more//
$another='capitilize me !';
echo'<br />';
//Hello World
//Mr.Fred Flinstone 4213 Rock Ridge Road zip:000024
//Capitalize the first word in this string.
//Capitilize me !
//To Test this set of functions go here--> 

No comments:

Post a Comment