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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:00:12+00:00 2026-05-30T05:00:12+00:00

I need help on how i can specify an array name or key using

  • 0

I need help on how i can specify an array name or key using a variable?
I’ve tried countless times and it never works

Before i get to the code, $games is the array, and i show it at the bottom

here is my code (i will show array example at the bottom)

$increment = 0; //increment i use in a while loop +1 per loop starting at 0
$increment2 = increment - 1; // to get the game number i need to minus 1 from $increment, 
//this works since the array starts at 0 and increment will be 1 when the while loop  starts.

$gamestotal = $games[totalGames]; //This number is different everytime, it is always 
//between 1-1000, it counts the number of a games a person has.
$gamesnpcommid = $games[$increment2][npcommid]; //each game has a unique code, i cURL this 
//info from Sony servers and return it in an array (array example below) This is the part 
//that is not working, to help understand please check array first, this variable is used   
//in the while loop and i need it to start at array 0 and keep returning the unique code
//until the loops stops at the final array number.

//Here is the loop

while($increment<$gamestotal)

    if($increment % 2 == 0){
    $increment=$increment+1;
        echo "<tr>";
        echo "<td style='background-color:#e6e8fa'>";
        echo $gamesnpcommid;
        echo "</td>";
        echo "</tr>";
    }
    else
    {$increment=$increment+1;
        echo "<tr>";
        echo "<td style='background-color:adeaea'>";
        echo $gamesnpcommid;
        echo "</td>";
        echo "</tr>";
    }

echo "</table>";

Everything is working completely fine but the array reference is not working ($gamesnpcommid), here is an example of what the array $games can look like:

The array is stored in variable $games,

Array
(
    [totalGames] => 110
    [0] => Array
        (
            [npcommid] => NPWR00507_00
            [platinum] => 0
            [gold] => 1
            [silver] => 11
            [bronze] => 32
            [total] => 44
            [lastupdated] => 1329258539
        )

    [1] => Array
        (
            [npcommid] => NPWR01140_00
            [platinum] => 1
            [gold] => 4
            [silver] => 8
            [bronze] => 29
            [total] => 42
            [lastupdated] => 1328586022
        )

    [2] => Array
        (
            [npcommid] => NPWR01118_00
            [platinum] => 0
            [gold] => 0
            [silver] => 3
            [bronze] => 8
            [total] => 11
            [lastupdated] => 1328067349
        )
    )

Can someone explain to me why, for example, if $increment2 = 2
and then when i try to reference the array by using $games[$increment2][npcommid] it does not return NPWR01118_00 like in the array?
But when i use $games[2][npcommid] it works?
I’ve done thorough debugging and i know the array works but i’m stumped at this point.

  • 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-30T05:00:14+00:00Added an answer on May 30, 2026 at 5:00 am

    try

    $games[$increment2]["npcommid"] 
    

    instead of

    $games[$increment2][npcommid]
    

    in other words, associative keys always have to be quoted.

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

Sidebar

Related Questions

I need to create HTML pop-up menu using Perl. Can anyone help me?
I need help, how can I learn this framework? Here's what I need to
Who can help me with regular expression? I need to remove a part of
I need some help modifying the Webform Module so that it can work for
I need to do a non greedy match and hope someone can help me.
I am stuck and in need of a hand. Hope someone can help? Anyone
I read the SDK document, but can not understand some details, need some help.
can someone help with this? I need the following function to do this... $x
Can anyone help, i trying to figure what i need to do, i have
I need to download jasper reports professional trail version, can anyone help?

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.