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

Image loading
Hi Developers,

I'm trying to display an image from images/image.gif getting the url from mysq

list files from folder, only one for each date
I have many files in a folder and wish to only list one of each date

these are the file names

IF Statement & Two Tables With Different Echoes
I'm retrieving two tables in a single query using UNION ALL, like so:

Code: $query = "SE

does anyone know a php script to send mail using gmails/googles free smtp server
cause i heard u can do that but i dont know how

download directory onto C drive
I am attempting (if this is possible) to write a routine to automatically dump the contents of a dir

DirectoryIterator and Hacked Website
Hi Everyone.

My problem:
Some one has been sneaking in to my website hidden Iframes. I've

PHP page is blank
Hi Everyone,

I have a site in which I am able to open the first PHP webpage in my browser but

jquery validation in codeIgniter
hai i need to add client side validation to my fiels which are selected in a forloop.the fields are

urldecode question
How would I format this line of code properly?

<?php echo urldecode($_GET['Title']); ?

Facebook status update API
Hello,

So, I'm trying to create my first Facebook application with PHP.

Basic ideas fo

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