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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:13:00+00:00 2026-05-31T21:13:00+00:00

I have an array where I want to get the next value. $sorting =

  • 0

I have an array where I want to get the next value.

$sorting = array(0 => "H 101", 1 => "S 101", 2 => "R 172", 3 => "D 141", 4 => "T 101", 5 => "K 101", 6 => "A 182", 7 => "G 101");

I have the current value taken from a SELECT statement. I have tried array_search but I can’t get it to do want I want.

Let’s say my current value is S 101, how can I get it to give me “R 172” as the next value which I then can use in a new SELECT statement.

And I also want it to get back to the first value (H 101) if the current value is the last (G 101).

  • 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-31T21:13:01+00:00Added an answer on May 31, 2026 at 9:13 pm

    Why have you explicitly specified the indices? These would be the same had you not done it.

    From what I understand, array_search would be suitable for what you want.

    $current = 'S 101';
    $nextkey = array_search($current, $sorting) + 1;
    if($nextkey == count($sorting)) {
        // reached end of array, reset
        $nextkey = 0;
    }
    
    $next = $sorting[$nextkey];
    

    HOWEVER, if I understand you correctly you’re looping through this array and making queries on it. How about posting what you want in terms of query result, as there may be a better solution (i.e. MySQL IN())

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have an array of table DDL queries and I want to get
So, basically I have an NSArray . I want to get an array with
In a view, I get an array of objects. I want to have a
I have an array that I want to sort based on the value of
I have one array. I want that array to retain its value between function
I have an array of strings: @array I want to concatenate all strings beginning
I have an array that I want on multiple pages, so I made it
I have a little problem, I have an array and I want to add
VISUAL C++ Question Hi, I have array of 3 elements and I want to
I have an array ($form) which retreives some information from $_POST: $form = $_POST['game'];

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.