Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Create a file named: Functions2.php in your text editor. 2. Create a function

ID: 3550970 • Letter: 1

Question

1.    Create a file named: Functions2.php in your text editor.

2.    Create a function (score) with five arguments that will add five values and return the result of that addition. Then echo five fictional students ($student) and give them each a score by calling the function with five random two-digit numbers for each student.  Obviously the variable $student will have to change after each function run and each function run should have different numbers.

3.    Create a function (math) with two arguments that will do three things: 1) add two values; 2) subtract two values; 3) multiply two values, and then return each of those results in an array. You will now display the results in two different ways: 1) call the function into a variable and display each of the three array pockets with labels; 2) use the PHP list function to give a variable name to each array pocket, then display each of the three variables with labels. Use different values in each of the two function calls.  Video 4 gives you an excellent example of what is needed here!

4.    Here is a sample of what your output should look like.

Brandon James:
Your Score = 242

Bugs Bunny:
Your Score = 278

Homer Simpson:
Your Score = 217

James T. Kirk:
Your Score = 254

Walter White:
Your Score = 202

==============

Add: 37
Subtract: 23
Multiply: 210

Add: 26
Subtract: 18
Multiply: 88


Explanation / Answer

<?

function score($x1,$x2,$x3,$x4,$x5){

return $x1+$x2+$x3+$x4+$x5;

}


echo "Brandom James:<br>Your Score:", score(1,2,3,4,5);

echo "James Hunt:<br>Your Score:", score(11,21,31,41,51);

echo "King James:<br>Your Score:", score(12,22,32,42,52);

echo "Niki Lauda:<br>Your Score:", score(13,23,33,43,53);

echo "Obama:<br>Your Score:", score(14,24,34,44,54);


function math($x,$y){

$add = $x+$y;

$sub = $x-$y;

$mul = $x*$y;

$arr = array("add"=>$add, "subtract"=>$sub, "multiply"=>$mul);

return $arr;

}


$result = math(12,23);

echo "Add: ", $result["add"], "<br>";

echo "Multiply: ", $result["multiply"], "<br>";


echo "Add: ", $add, "<br>";

echo "Multiply: ", $mul, "<br>";