Scroll through an object array in php using foreach

Asked

Viewed 255 times

0

I’m having trouble displaying the information in a simple table in html, I’m trying everything, the php code is this:

<?php
$header = true;
echo '<html><body><table><meta http-equiv="Content-Type" 
content="text/html"; 
charset="iso-8859-1">';
if ($header){
  foreach ($obg->conteudo->coluna as $col => $valor){
         echo'<th>'.htmlentities( $valor ).'</th>';
  }
   $header=false;
}
echo '</table></body></html>';
?>

The variable $obg = simplexml_load_string(uma variavel com xml string);, that is, she is an object.

The error is as follows:

PHP Notice: Trying to get Property of non-object

  • What’s the error line? On the foreach line? If that’s the case, probably $obg->content is not an object

  • It’s right on Echo

  • Makes a var_dump($obg); before the foreach to see what kind of object is.

  • Object(Simplexmlelement)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.