![]() |
Given an unsorted array, the task is to find the mean (average) and median of the array in PHP. we will see the approach and code example to solve this problem. ApproachTo find the mean of an array, we need to sum up all the elements in the array and then divide the sum by the total number of elements in the array. To find the median of an array, we first need to sort the array in ascending order. If the array has an odd number of elements, the median is the middle element. If the array has an even number of elements, the median is the average of the two middle elements. Example: This example shows the implementation of the above-explained approach.
Output Mean of Unsorted Array: 11.666666666667 Median of Unsorted Array: 12.5 |
Reffered: https://www.geeksforgeeks.org
PHP |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |