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

Change log of Cost centre change in Plant maintenance order
Hi,
How to view Change log of Cost centre in Plant maintenance order. Not visible thru 'Docume

Pls help with PHP
Pls can anyone direct me on how to create a user account for a customer. For example i want know if

CODE NOT WORKING
Code: [Select]<?php
//include shared codes

include '../lib/common.php';
include

values not being entered into table
hi. I;ve created a form, so that when a user enters data into it, it gets added to a table in a data

PHP Surveys
I really would like some advice.

If you have a client come to you asking for a survey to be d

$_FILES array
Ok,

I just started experimenting with PHP today. My goal right now is to have people be able

Delete all files in folder except with certain name
I have a script that I want to delete all files in a folder (taken from a database) except for one n

php/xmlrpc class issue
I am working on xml-rpc in php to start with.

I have a class that only has variables defined

Select question
Hi,

First I would like to say that php is pretty new for me..
so please don't shoot me if

Form a inline view based on the results of the previous query?
Hi Experts,
Can we form a inline view on the results of a previous query (another inline view)?

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