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) {
Did you know?Explore Trending and Topic pages for more stories like this.
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?
No comments posted yet

Your Answer:

Login to answer
241 Like 5 Dislike
Previous forums Next forums
Other forums

help with contest script
I would like to code a contest script to my site but i don't know how. Could someone just give me pu

Extract text from string
Hi folks,

I have a string that looks like this:

aaaaaaaaaa:
bbbbbbbbbb (ccccccccc)

array & querys help/advice.
Ok so here goes , I have a mysql database and basically here's what I need to do.

// foreach

need help in creating captcha
hi i have a problem creating captcha system. i create some basic script for image displaying but it

Inserting multiple records from single form
I've found a number of threads that deal with this issue, but I'm new to php and coding language so

How would I protect......
I have a from, actually, a good amount of forms. How can I make it so you can't type the characters:

Help with writing "$" with fopen
I just can't get my syntax correct. Could someone help me please? I am trying to write a connect fil

Web Host List
Here is a list of web hosts that offer PHP and MySQL. It is no where near a full list, but it is mos

Concatenate two strings ???
I have string one $string1 and another $string2.

How to concatenate (add) both of them $str

Batch Session SM35 stuck in status 'in Background
Hi Experts,

I am facing a problem with Batch Input session SM35.

The batch se

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