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

  • Home
  • SEARCH
  • 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
  • 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-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

Ask A Question

Stats

  • Questions 539k
  • Answers 539k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The section from the Swing tutorial on How to Use… May 17, 2026 at 2:19 am
  • Editorial Team
    Editorial Team added an answer register_namespace was only introduced in lxml 2.3 (still beta) I… May 17, 2026 at 2:19 am
  • Editorial Team
    Editorial Team added an answer There is no hard and fast rule here. Your Json… May 17, 2026 at 2:19 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Suppose you have a sorted range (x to y) of values in an array.
Suppose I have an array of values [a,b,c,d,...] and a function f(x,...) which returns
Suppose I have an array of nodes (objects). I need to create a duplicate
Suppose I have a sorted array of integers int[] , and I want to
Suppose I have an_array = [[2, 3], [1, 4], [1, 3], [2, 1], [1,
Suppose I have following data in my game. I have developed game in cocos2d.
Suppose I have a treeview, where each treenode contains an id for a different
Suppose I have a method to return a list of keys in a dictionary,
Suppose I have a function function fetchAll(){ $args = func_get_args(); $query = array_shift($args); $query
Let's suppose that we have multi-site CMS and every website in this CMS having

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.