Declaring a Function that Requires an Argument

Chapter 7 #135 - Martha's CIS 52

ASSIGNMENT/EXPLANATION

In this example, the function printBR() "expects a string, so the variable name $txt is placed between the parentheses when the function is declared. Whatever is passed to printBR() will be stored in this $txt variable. Within the body of the function, line 3 prints the $txt variable, appending a <br /> element to it." (135) A programmer can use this function instead of the built-in print() and save the bother of typing the <br /> element. Pretty cool, huh?

Exercise

This is a line.
This is a new line.
This is yet another line.

CODE

<?php 
function printBR($txt) {
echo $txt."<br />";
}
printBR("This is a line.");
printBR("This is a new line.");
printBR("This is yet another line.");
?>