Link to home
Start Free TrialLog in
Avatar of Bill Sullivan
Bill SullivanFlag for United States of America

asked on

Receiving "Invalid argument supplied for foreach() " when parsing XML data

Hi:
I receive "Invalid argument supplied for foreach()" when I am parsing an XML file.  The program goes ahead and parses out the data, but I need to understand the warning, then do what is needed to get rid of it.  My code is below.  It is the second 'foreach' that throws the warning (5th line).

Any help will be much appreciated!

foreach($data->STRUCTURES->ROOF as $roofingItem) {
      $count++;
}
while($i <= $count) {
      foreach($data->STRUCTURES->ROOF[$i]->LINES->LINE as $lineitem) {
            $type=$data->STRUCTURES->ROOF[$i]->LINES->LINE[$ii]['type'];
            if($type == "VALLEY") {
                  $valley=$valley + $data->STRUCTURES->ROOF[$i]->LINES->LINE[$ii]['length'];
            }
            if($type == "RIDGE") {
                  $ridge=$ridge + $data->STRUCTURES->ROOF[$i]->LINES->LINE[$ii]['length'];
            }
            if($type == "Eave") {
                  $eave=$eave + $data->STRUCTURES->ROOF[$i]->LINES->LINE[$ii]['length'];
            }
            if($type == "Rake") {
                  $rake=$rake + $data->STRUCTURES->ROOF[$i]->LINES->LINE[$ii]['length'];
            }
            if($type == "Flashing") {
                  $flashing=$flashing + $data->STRUCTURES->ROOF[$i]->LINES->LINE[$ii]['length'];
            }
            if($type == "StepFlash") {
                  $stepflash=$stepflash + $data->STRUCTURES->ROOF[$i]->LINES->LINE[$ii]['length'];
            }
            if($type == "HIP") {
                  $hip=$hip + $data->STRUCTURES->ROOF[$i]->LINES->LINE[$ii]['length'];
            }
            $ii++;
      }
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Hello Bill, 

please describe what the error was and what was the helpfull solution in my comment or ask EE support to remove this Question and refund your points.