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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:36:54+00:00 2026-06-15T16:36:54+00:00

This is an odd question because I don’t know what to call it! I

  • 0

This is an odd question because I don’t know what to call it! I have an array with a list of numbers. These numbers are automatically detected, so I can’t set them.

The numbers come in ranges like “001, 002, 003, 004, 005, 006” or “001, 003, 004“.
Note that in the first list of numbers, they all go up (1,2,3,4,5,6) but in the second one they are less ordered (1, 3, 4).

My complicated question is this: How do I detect the first available array entry? For the first one, I would want “007” and for the second one “002“. How on earth do I detect this and add an array element to fill the slot??!

The system supports unlimited slots, so there is no actual list of slots to compare against.

Here is my code so far:

$currentunits = array("001", "003", "004", "006");
$currentunits = array_diff($currentunits, range("001", "999"));
echo "<pre>";
print_r($currentunits);

Thanks in advance, and I hope I have not confused you!

  • 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-15T16:36:55+00:00Added an answer on June 15, 2026 at 4:36 pm

    Assuming that your 001 is the string "001" and not the number 1 (etc):

    function findNextSlot($array) {
        $counter = +$array[0];
        foreach ($array as $current) {
            if (sprintf("%03d", $counter) != $current) {
                return sprintf("%03d", $counter);
            }
            $counter++;
        }
        return sprintf("%03d", $counter);
    }
    echo findNextSlot(array("001", "002", "003", "004", "005", "006")); // "007"
    echo findNextSlot(array("001", "003", "004")); // "002"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is a rather odd question, please don't flame me :) I
This might sound a bit of an odd question but I know what I
I guess this is kind of an odd question but I have tried setting
This is not exactly a straight-out question because I have just solved it, but
This question is long winded because I have been updating the question over a
This question may seem a little odd/weird, but I have two UIWebViews, one of
Sorry about the vague question title, but I have these typedefs here: typedef std::list<AnimationKeyframe>
This may be a bit of an odd question, and what I have in
this is somewhat of an odd question. I wrote a C function. Its 'like'
This will be probable quite odd question. But i thought I will give it

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.