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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:39:42+00:00 2026-05-19T23:39:42+00:00

Does next() and prev() work on associative arrays? I’m trying to traverse through a

  • 0

Does next() and prev() work on associative arrays?

I’m trying to traverse through a dataset that uses two records to describe one “game” if you will. So when I’m on the second record w/ matching id i need to look at the record before and grab eg_item['final_score'].

{"id":"75", "team_name":"TEAM1", "home_team_name":"TEAM1", "image":"TEAM1_HOME.png", "final_score":"37"}, 
{"id":"75", "team_name":"TEAM2", "home_team_name":"TEAM2", "image":"TEAM2_AWAY.png", "final_score":"10"}, 
{"id":"76", "team_name":"TEAM1", "home_team_name":"TEAM1", "image":"TEAM1_HOME.png", "final_score":"10"}, 
{"id":"76", "team_name":"TEAM2", "home_team_name":"TEAM2", "image":"TEAM2_AWAY.png", "final_score":"14"},

All of the examples I’m finding use lame array('one','two',three') type examples that just don’t help.

code sample:

foreach( $json_output as $eg_item ) :

    if( $this_game_id == $last_game_id ) :
        // get this records info
        $b_score = $eg_item['final_score'];
        $b_team_name = $eg_item['team_name'];
        prev( $json_output );
            // get previous records info
        $a_score = $eg_item['final_score'];
        $a_team_name = $eg_item['team_name'];
        $a_game_id = $eg_item['id'];
        // put pointer back
        next( $json_output );    
    else :  
        // skip next record     
    endif;

endforeach;
  • 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-19T23:39:43+00:00Added an answer on May 19, 2026 at 11:39 pm

    That looks like an array of associative arrays, right? If so, loop through them by index 2 at a time, then you can look at the current inner array and the previous inner array in each iteration of the loop:

    for ($i = 1; $i < count($array); $i+= 2) {
      $current = $array[$i];
      $last = $array[$i-1];
      //$current['final_score'], $last['final_score'], etc
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

next() in python does not work. What is an alternative to reading next line
I am trying to create a simple image slideshow that fades in and out
why does .next() returns 'undefined'? http://jsfiddle.net/radek/sD6JB/2/ html <button value=login|basic class=square_button button_background type=button> run </button>
In pdb the next instruction does not step over list comprehensions, instead it steps
Does it work on your machines? I don't know how to use it- i
Very next to XML, I've developed an XML sheet, alongside a XSD schema and
Considering next simple example: The header: // a.hpp #ifndef A_HPP #define A_HPP #include <memory>
there i have created a program with a tab button and page number. all
hello i am stuck with jquery tablesorter: http://tablesorter.com/docs/index.html#Examples and would be grateful if some
I've got basically 5 windows in my iPad-application (created with Appcelerator Titanium) and want

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.