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 1102581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:12:31+00:00 2026-05-17T01:12:31+00:00

Suppose you have an array value => timestamp. The values are increasing with the

  • 0

Suppose you have an array “value => timestamp”. The values are increasing with the time but they can be reset at any moment.

For example :

$array = array(
1 => 6000,
2 => 7000,
3 => 8000,
7 => 9000,
8 => 10000,
9 => 11000,
55 => 1000,
56 => 2000,
57 => 3000,
59 => 4000,
60 => 5000,
);

I would like to retrieve all the missing values from this array.

This example would return :

array(4,5,6,58)

I don’t want all the values between 9 and 55 because 9 is newer than the other higher values.

In real condition the script will deal with thousands of values so it need to be efficient.

Thanks for your help!


UPDATE :
The initial array can be ordered by timestamps if it is easier for the algorithm.


UPDATE 2 :
In my example the values are UNIX timestamps so they would look more like this : 1285242603 but for readability reason I simplified it.

  • 1 1 Answer
  • 1 View
  • 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-05-17T01:12:32+00:00Added an answer on May 17, 2026 at 1:12 am

    Here’s another solution:

    $prev = null;
    $missing = array();
    foreach ($array as $curr => $value) {
        if (!is_null($prev)) {
            if ($curr > $prev+1 && $value > $array[$prev]) {
                $missing = array_merge($missing, range($prev+1, $curr-1));
            }
        }
        $prev = $curr;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have an array of values [a,b,c,d,...] and a function f(x,...) which returns
Suppose you have a sorted range (x to y) of values in an array.
For example, suppose I have {={1,2,3,4,5}} in a cell. Is there any way to
Suppose i have an array $x = (31,12,13,25,18,10); I want to reduce this array
Suppose I have an array that mimics a database table. Each array element represents
Suppose I have an array of nodes (objects). I need to create a duplicate
Suppose I have an array like this: $array = array(a,b,c,d,a,a); and I want to
I recently came across a question somewhere: Suppose you have an array of 1001
I have a question about Quantifiers. Suppose that I have an array and I
Suppose that I have a 2D array (matrix) in Java like this... int[][] MyMat

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.