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?

No comments posted yet

Your Answer:

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

Retail terminologys not been altered after activing Retail System
Hi, All

After I active Retail System via TCode SWF5, the terms does not been changed, th

PHP SUBMIT
Code: <input name="doLogin" type="image" src="images/loginsubmit.jpg

RTF fomatting to email content
Im trying to sen an email with content is picked up from a rtf-file (file_get_contents('*.rtf'). Mai

Mail Form receiving emails with no content
Hi, I hope someone here can help me.
I have a simple form in my website, it was working OK, after

contact form - output to page and email
I have the following in my controller:

$message['name'] = htmlentities(strip_tags(trim($_POST

Blocking video streaming
Hello everyone,

I post a message here because i didn't find any solution yet.
I just finis

puting for loop in 1 value
hi ,

how do i put this code in 1 value:
Code: <?php
for ($i=1; $i<=5; $i

Strip Slashes Help
I've got a script that i've downloaded of the net to edit multiple fields from my sql database, and

C++ API to Oracle dB
I need to perform a select command to the Oracle dB to obtain information from a table.
What libr

controlling/creating accounts with privileges
hi all,
i'm trying to figure out how i can create/control account with privileges, for instance a

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