Array disappearing in foreach loop


Posted on 16th Feb 2014 07:03 pm by admin

Okay, I have this problem where an array will become undefined in a foreach loop.

Here is the function plus a couple comments:
Code: [Select]function mineResources($nation) {
global $db;
$resources = $nation['resources'];

//Right here $resources would work

$sectors = $db->getSectorList($nation['id']);
foreach($sectors as $sector) {
//In here, $resources is empty
$sectorResources = $sector['resources'];
foreach($sectorResources as $key => $sResource) {
//Does nothing because $resources is empty when it gets here.
$resources[$key] += $sResource;
}
}
$db->updateCountryInfo($nation, array("resources" => $resources));
}
$db is a global array that holds database information. $nation is an array that holds a nation's data. All arrays work except for $resources and even $resources work outside of the foreach loops. Any ideas why this is happening?

241 Like 5 Dislike
Previous php-forum Next php-forum
Other php-forum

Credit card verification
I have a client who wants to process credit card transactions from his web site rather than the goin

Call to undefined function mysql_fetch_accoc()
New to php/mysql coding. What's wrong with this sequence, or am I
just not seeing to obvious?

gather checkbox data from form into email
Hello all,

First, i'd like to thank everyone who responded to my previous posts regarding set

Save data in input fields when they press "BACK BUTTON"
Hi, this is html form: And let's say they get a error "Please enter ur title must be more then

Multi-image upload problems
Lets see if I can get some help on this one. Can anyone show me what I am doing wrong here. I'm just

javascript in php code causes page to display white
Hi All,

Odd one this, I've got the following code (below) which is a simple log in form. The

Help with explandable category tree
I have the below query:

SELECT l1.id as lev1_id,l2.id as lev2_id,l3.id as lev3_id,l1.categ

Help with forum quoting?
Hi im working on a forum and I have alomost finished it but i want a user quote system like twitter

Count
Getting the same count everytime

Code:
$visitquery = mysql_query("SELECT COUNT(*) FR

why does my session end?
my connect.php starts the session just so you know
i can navigate arround my site fine except whe

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash