Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will create 2 new functions. Each will be in their own separate PHP file. Then you will pull those functions into a main PHP

You will create 2 new functions. Each will be in their own separate PHP file. Then you will pull those functions into a main PHP file using require_once. By using require_once, you will be able to call those functions found in those PHP files. Next you will practice using numerically indexed arrays by iterating over 2 equal length arrays using a for loop and calling the functions you pulled in using require_once.

(3 pts) Create a new php file named add.php. In the file, define a function named add_two_numbers which takes 2 integers as arguments. The return value for the function should be the sum of the 2 numbers. (3 pts) Create a new php file named subtract.php. In the file, define a function named subtract_two_numbers which takes 2 integers as arguments. The return value for the function should be the difference of the 2 numbers. (5 pts) Create a new php file do_math.php. Use require_once to include the functions from add.php and subtract.php into the current scope. Take the following list of numbers, and put them into arrays. array_one: 3, 4, 9, 1, 3, 4 array_two: 28, 92, 6, -4, 1, 4 (5 pts) Use a for loop to iterate through the 2 arrays via their numerical index. You can assume the arrays are equal length, so you can use count or sizeof to get the length of one of the arrays to use for the for loop. Call both add_two_numbers and subtract_two_numbers for each pair of values. For example, for index 1, you would use the value 4 from array_one and the value 92 from array_two. Print out the value of each argument, then the value of the sum, then the value of the difference. For example: Arguments: 4 and 92 Sum: 96 Difference: -88

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

9. Power and politics can be destructive forces in organizations.

Answered: 1 week ago