Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

  1. Use print_r( ) function to print the array.
  2. Use sort( ) and rsort( ) functions to print values in the ascending and descending order.
  3. 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

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

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

2. What are the potential strengths of group discussion?

Answered: 1 week ago