-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultParameters.php
More file actions
28 lines (22 loc) · 832 Bytes
/
DefaultParameters.php
File metadata and controls
28 lines (22 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
function greetFriend($name = "old chum")
{
echo "Hello, $name!";
};
greetFriend("Marvin"); // Prints: Hello, Marvin!
greetFriend(); // Prints: Hello, old chum!
/**
* Write a function calculateTip() which takes a number representing the total cost of a
* meal as its first argument. It should also take a second, optional argument—an integer
* representing the percent tip desired (eg. 25 will indicate a 25% tip should be calculated).
* If no second argument is passed in, the function should default to a 20% tip.
* The function should return the new total—the previous total plus the calculated tip.
*
*/
function calculateTip($totalCost, $porcentTip = 20)
{
return $totalCost * (1 + ($porcentTip / 100));
}
echo calculateTip(100, 25);
echo "\n". calculateTip(100);
echo "\n". calculateTip(65, 15);