Skip to content

Instantly share code, notes, and snippets.

@itskingori
Created December 20, 2013 06:59
Show Gist options
  • Save itskingori/8051322 to your computer and use it in GitHub Desktop.
Save itskingori/8051322 to your computer and use it in GitHub Desktop.
Function With Arguments
<!DOCTYPE html>
<html>
<head>
<title>Exercise 09: Function with arguments</title>
</head>
<body>
<?php
// First, create a function to accept two arguments, perform a calculation
// using them, and then return a sentence with the result to the browser.
// The function will calculate the area of a rectangle, with the two
// arguments being width and height. The sentence to be returned is;
// "A rectangle of length $l and width $w has an area of $area."
// Where $l and $w are the arguments and $area is the result.
// Create function to calculate area
function area($l, $w) {
// Calculate the area
$area = $l * $w;
// Output the sentence replacing the variables where necessary
echo "A rectangle of length ".$l." and width ".$w." has an area of ".$area.".<br/>";
};
// Call the function with some values as an example
area(2,3);
area(4,5);
area(6,7);
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment