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

filesize() returns 0
I have a socket program that runs in an infinite loop, listening for connections, in this socket I h

PHP Display Telephone Number On Referrer
I have used the php below to show a different telephone number in the header of the site depending u

do while conditions
i want to display 6 images in a 2x3 table
now what would be the correct logic to
count that th

Changes to hosting company's server has affected web contact form
I started a thread a couple of months ago about the contact forms on my client's website. Basically

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

Code: $modifiedData = array(

Hit counter updating once per IP - IP HIT COUNTER
I have a hit counter, for the amount of views on a tutorial.
It'll do the query and then do..

reading xml faster than DB call?
I am trying to optimize a high traffic website, and I enabled a feature where there are three photos

Converting from one format to another
"I have got a date in DD/MM/YYYY but I need it in MM-DD-YYYY. Help!"

how to use two buttons with php
hi i have one form. there are three fields which are to be filled by the user. and then there are tw

post to self
Trying to get my form to submit to itself. However I am also trying to use an image for my submit bu

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