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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:30:39+00:00 2026-05-27T18:30:39+00:00

I’m working with some data which is being retrieved from my database. It’s placed

  • 0

I’m working with some data which is being retrieved from my database. It’s placed into a 2-dimensional* array and manually sets the index based upon the ID of the data in the database.

* It’s more than two-dimensional, but I only need to work with 2 dimensions of it.

This is the Array in question:

Array
(
    [error] => Boolean(false)
    [results] => Array
        (
            [1] => Array
                (
                    [0] => title1
                    [4] => title2
                )
            [3] => Array
                (
                    [0] => title3
                    [1] => title4
                    [2] => title5
                )
            [4] => Array
                (
                    [0] => title6
                    [1] => title7
                    [3] => title8
                )
        )
)

Within this Array, I only need to work with the “results” part of it, hence making the problem Array 2-dimensional.

Some voodoo-magic happens in my script and I’m told the index for the first array and the index for the second array, and then I pull the value from the second array.

Let’s say that I wanted to get the value “title5”. My script would tell me that I need to use index 3 and then index 2.

I’ve done all of that, but it’s this next part of the task that I’m stuck on, and have no-idea how to even attempt.

After retrieving “title5” I want to retrieve the indexes for the next and previous item, so in this case for both “title4” and “title6”. In the event of there not being a previous value (say we originally pulled “title1”) then I need some way of identifying this, like with a false boolean. And likewise for if there is no “next” value either.

By retrieve the indexes I mean, for example: title4 = 3 & 1 and title6 = 4 & 0

Does anybody have any ideas how I should go about doing this? I’m not looking for someone to do the work for me necessarily, but some pointers would be greatly appreciated. In the mean time I’ll keep experimenting. Thanks!

Note:

  • Titles aren’t actually called title1, title2, etc. So I can’t just decrement a number and do a search.
  • 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-27T18:30:40+00:00Added an answer on May 27, 2026 at 6:30 pm

    I edited @Jonathan Rich’s answer a little bit to obtain my actual solution. Where $firstIndex and $secondIndex are the two index that I already know.

    //my already known indexes
    $firstIndex = 3;
    $secondIndex = 2;
    //
    $prevIndex1 = null;
    $prevIndex2 = null;
    $last_was_value = false;
    $nextIndex1 = null;
    $nextIndex2 = null;
    foreach ( $articles['results'] as $index => $value ) {
        foreach ( $articles['results'][$index] as $index2 => $value2 ) {
            if ( ($index == $firstIndex) && ($index2 == $secondIndex) ) {
                $last_was_value = true;
            } else if ($last_was_value == true) {
                $nextIndex1 = $index;
                $nextIndex2 = $index2;
                break 2;
            } else if ($last_was_value == false) {
                $prevIndex1 = $index;
                $prevIndex2 = $index2;
            }
        }   
    }
    echo "<br />PREV: $prevIndex1 & $prevIndex2<br />";
    echo "NEXT: $nextIndex1 & $nextIndex2<br />";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I have a text area in my form which accepts all possible characters from
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

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.