Invert PHP Xml view

Asked

Viewed 39 times

1

How do I invert the display of an xml in PHP? Code:

$xml = simplexml_load_file('link.xml');
foreach($xml->VERSAO as $versao) { ?>
<tr>
   <td width="10%"><center> <?php echo $versao->VERTEXT ?> </center></td>
   <td width="90%"><?php echo $versao->RESUMO ?> </td>
</tr>    
<?php } ?>

It starts displaying from the first item to the last, how do I print from the last to the first?

1 answer

2


Makes a for common starting from the higher value to the beginning:

Example:

$xml = simplexml_load_file('link.xml');
for($i = (count($xml->VERSAO) - 1); $i >= 0; $i--) { ?>
<tr>
   <td width="10%"><center> <?php echo $xml->VERSAO[$i]->VERTEXT ?> </center></td>
   <td width="90%"><?php echo $xml->VERSAO[$i]->RESUMO ?> </td>
</tr>    
<?php } ?>
  • 1

    Thank you very much, that’s just what I needed.!

Browser other questions tagged

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