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

  • Home
  • SEARCH
  • 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 8427173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:43:17+00:00 2026-06-10T04:43:17+00:00

I created an associative array within an associative array. However, I ran into a

  • 0

I created an associative array within an associative array. However, I ran into a problem when I wanted to increment the pay of the elements. The PHP code is as follows:

$assoc_in_assoc['Manager']['name'] ="Jim";
$assoc_in_assoc['Manager']['pay'] = 7000;
$assoc_in_assoc['Manager']['Location'] ="2nd Flooe";
$assoc_in_assoc['Accountant']['name'] ="Mr Mike";
$assoc_in_assoc['Accountant']['pay'] = 4000;
$assoc_in_assoc['Accountant']['Location'] ="Account Office";
$assoc_in_assoc['Accountant']['Special Skills'] ="Charterd Accountant";

// Lets give each one a raise of 1000 dollars
foreach ($assoc_in_assoc as $rec){
echo "<pre>";
$rec['pay'] = $rec['pay']+ 1000;
echo print_r($rec);
echo "</pre>";
}// end for each
echo "<pre>"; echo "<hr/>";
echo print_r($assoc_in_assoc);
echo "</pre>";
?> </body> </html>

Can any one please suggest how to increment the pay with out converting the array structure?

I have solved the problem by changing the structure of the array from Associative into an Associative aray …to an Associative array with in an indexed array.

Solution:

<html> <head> </head> <body> <?php 
echo "Associative array with in Associative array";

$assoc_in_assoc['0']['appointment'] ="Manager";
$assoc_in_assoc['0']['name'] ="Jim";
$assoc_in_assoc['0']['pay'] = 7000;
$assoc_in_assoc['0']['Location'] ="2nd Flooe";
$assoc_in_assoc['1']['appointment'] ="Accountant";
$assoc_in_assoc['1']['name'] ="Mr Mike";
$assoc_in_assoc['1']['pay'] = 4000;
$assoc_in_assoc['1']['Location'] ="Account Office";
$assoc_in_assoc['1']['Special Skills'] ="Charterd Accountant";

// Lets give each one a raise of 1000 dollars
$count=0;
foreach ($assoc_in_assoc as $rec){
echo "<pre>";
$assoc_in_assoc[$count]['pay'] += 1000;
$count++;
echo "</pre>";
}// end for each
echo "<pre>"; echo "<hr/>";
echo print_r($assoc_in_assoc);
echo "</pre>";
?> </body> </html>

Can any one please guide me to an exhaustive source of PHP array discussion? Not only the introduction but the detailed explanation of all aspects of arrays.

  • 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-10T04:43:18+00:00Added an answer on June 10, 2026 at 4:43 am

    You could do something else to keep the same structure as before. Instead of doing a simple foreach, you can do the following :

    foreach($assoc_in_assoc as $key => $rec){
        $assoc_in_assoc[$key]['pay'] += 1000;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When declaring an Array in PHP, the index's may be created out of order...I.e
I want to transform the 'values' array created by xml_parse_into_struct() into a bunch of
I am using eval to create an associative array from php built in xml
I created associative array as below $query = SELECT word,meaning1,meaning2 FROM dictionary; $results =
I have my XML feed being created from an associative array. Using new DOMDocument('1.0','UTF-8');
I would like to create an associative array. I believe I can benefit of
I am trying to create an associative array that collects the following (existing on
I have a page that creates an associative array, then passes it as a
Suppose you have an associative array $hash['Fruit'] = 'Apple'; $hash['Name'] = 'Jeff'; $hash['Car'] =
Is it possible to return groups as an associative array? I'd like to know

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.