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

script is pulling more then they have....
I have this script for my game where they can change there race. This will cost them 2,500 points. H

Is it possible to view php source code??
Hi All

I was just wondering if it's possible to view a websites php source code?
I know

FlashVar function how to insert variables
Hi guys. Im new in this forum and also new in php programming. Can you help me about this code?
<

UPLOAD IMAGES NOT WORKING!
Hi there i have a upload script in which it uploads the picture to a folder than creates two thumbna

Sort a two dimensional array.
Hi. I've set up a two dimensional array that reads as follows:

Code: $modifiedData = array(

Please help with code for SMTP authenticated PHP email form
Hello, I'm creating a PHP email form, and for this particular server, I have to use SMTP Authenticat

admin with my register system?
Hey i wana make it so i can make a admin level on my register system , I'm kinda new to php to im no

 formating when pulling data from a mysql database 
Ok so Im not to sure if this is the right thread to post in but here is my catch 22 issue.

I

Help Optimizing code
Good Morning,

I wrote a small import function for a website of mine and I know there has to b

PHP Redirecting
Hello everyone. Is there a way to redirect people to pages within a statement in PHP? Since there is

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