Question
Create a PHP file and include necessary statements to complete the following 4 problems: 1. Define two variables and assign two positive numbers as their
Create a PHP file and include necessary statements to complete the following 4 problems:
1. Define two variables and assign two positive numbers as their values.
Compute their sum, difference, and product.
Use echo statement to display the sum, difference, and product of those values.
Sample output:
Number 1: 10
Number 2: 20
Sum: 30
Difference: -10
Product: 200
2. Define an array of 10 numbers. Use a loop to display square of each element in the array.
Sample output:
Number: 2, Square: 4
Number: 5, Square: 25
. . . 3. Define an array of 10 numbers between -50 and 50. Include some duplicate values.
- Use print_r( ) function to print the array.
- Use sort( ) and rsort( ) functions to print values in the ascending and descending order.
- Use array_unique( ) function to print unique values. Note: array_unique( ) method returns an array of unique values.
Sample output:
Original array:
Array ( [0] => 30 [1] => 3 [2] => -25 [3] => -5 [4] => 20 [5] => 40 [6] => -15 [7] => -10 [8] => 20 [9] => 30 )
Sorted array in the ascending order:
Array ( [0] => -25 [1] => -15 [2] => -10 [3] => -5 [4] => 3 [5] => 20 [6] => 20 [7] => 30 [8] => 30 [9] => 40 )
Sorted array in the descending order:
Array ( [0] => 40 [1] => 30 [2] => 30 [3] => 20 [4] => 20 [5] => 3 [6] => -5 [7] => -10 [8] => -15 [9] => -25 )
Unique values:
Array ( [0] => 40 [1] => 30 [3] => 20 [5] => 3 [6] => -5 [7] => -10 [8] => -15 [9] => -25 )
4. Display the sum of the positive numbers in the array defined in part 3.
Sample output:
Sum of the positive values: 143
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started