Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7770147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:20:14+00:00 2026-06-01T16:20:14+00:00

I have an array of numbers and some numbers are obviously too big or

  • 0

I have an array of numbers and some numbers are obviously too big or too small relative to them all. I wonder if there is already some kind of function or algorithm that I can use in order to remove these records from array.

Here is an example of array

8
7
21
1330829238608
6
7
188
8
25
92433
19
6

At the moment all I can think about is just check if number is more than 1k or less than 1k and then do not allow it. But still I get problem since 188 does not belong here either.

Is there any good way that I can get majority of close numbers from this array and produce something like

8
7
6
7
8
6

This is what I have so far

<?php

echo '<pre>';
$startArray = Array(8, 7, 21, 1330829238608, 6, 7, 188, 8, 25, 92433, 19, 6);

print_r($startArray);

for ($i = 0; $i < count($startArray); $i++) {
    if ($i != count($startArray) - 1) {
        if ($startArray[$i] - 10 <= $startArray[$i + 1]) {
            echo $startArray[$i] . '<br />';
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:20:15+00:00Added an answer on June 1, 2026 at 4:20 pm

    This can be optimized but this is what I figured out, works with diff of 20%, you can change it to whatever % you want, of course.

    <?php
    
    $startArray = array(8, 7, 21, 1330829238608, 6, 7, 188, 8, 25, 92433, 19, 6);
    $groupArray = array();
    $startArrayCount = count($startArray);
    
    for ($i = 0; $i < $startArrayCount; $i++) {
        // 20% of current value
        $valueDiff = ($startArray[$i] / 100) * 20;
    
        // Get minimal and maximal value
        $maxValue = ($startArray[$i] + $valueDiff);
        $minValue = ($startArray[$i] - $valueDiff);
    
        // Print it out
    //    echo 'Diff: ' . $valueDiff . '<br />';
    //    echo 'Max: ' . $maxValue . '<br />';
    //    echo 'Min: ' . $minValue . '<br />';
    
        $groupArray[$i] = array();
        for ($n = 0; $n < $startArrayCount; $n++) {
            if ($startArray[$n] <= $maxValue && $startArray[$n] >= $minValue) {
                // echo 'TRUE: ' . $startArray[$n] . '<br />';
                array_push($groupArray[$i], $startArray[$n]);
            }
        }
        //echo '<hr />';
    }
    
    // Getting arrays that have most members in it
    $max = count($groupArray[0]);
    foreach ($groupArray as $group) {
        if (count($group) > $max) {
            $max = count($group);
        }
    }
    
    // Taking all those arrays and combining them in one
    $finishArray = array();
    foreach ($groupArray as $group) {
        if (count($group) == $max) {
            foreach ($group as $key) {
                array_push($finishArray, $key);
            }
        }
    }
    
    // Combining all values
    $total = null;
    foreach ($finishArray as $num) {
        $total = $total + $num;
    }
    
    // Getting average
    $average = $total / count($finishArray);
    
    echo $average;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume that we have an array of small (about 10^(-15) ) double numbers in
Lets say I have an array numbers that contains the following values: int numbers
I have an array of numbers: @numbers = 1,2,3,6,8,9,11,12,13,14,15,20 and I want to print
Consider the following scenario . I have an array of numbers: [ 1,2,3,4 ]
I have an array of phone numbers, and I need a fast way to
I have a PHP array with numbers of ID's in it. These numbers are
I have a array of integer numbers (say 1,2,3,4,5 or 1,2,3, ... 10 or
I have an array of prime numbers from 2 to 997. How do you
I have an array which contains 12 numbers and I want to save this
I have a nested array with valid numbers => data:- $validData = array(array(1 =>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.