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

Taylor Series Function
So I am working a a project for my intro C++ class, and I am having some trouble with a function for

Stumped by Third Day of Month problem
I am trying to build an algorithm that will essentially do this:
Code: [Select]$this_month = Oct

How do i use vars in an array
Hiya peeps!

How do I use a var in an array. You will see $id but it isnt working.


Word Trimming
Hi Guys & Gals!!

Hope you are all ok....

I need some help with the following

Need help with an email blocker for a guessbook
I am new with php and here is a simple guessbook page but I am being hit with spam from a group of t

remove a ; from emails in textarea
Code: <?php

session_start();

$database_host = "localhost&qu

private constructor
Hello,

Can we create a constructor as private? If yes, what is the use of it? If no, why can'

Data storage spaces in varchar2
Trying to understand what's happening.
I am selecting a value from a table that is defined as c

fwrite error
Hi All,
Does anyone know what is causing the error in this code?

Code: <?
$error

try catch error
I have been trying try catch but, I can't get it to work. The code opens a non existing file called

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