is it possible to use values that are obtained within a loop/function out side the loop/function where it is used or called?
below is my function
function off($limit)
{
$string=file_get_contents("feed.xml");
$xml=simplexml_load_string($string);
foreach ($xml->FOUND->CAT as $place)
{
$limits = $place->CORDS;
$rate=$place->STARS;
$phone=$place->PHONE;
}
}
Im calling it to a php file which has html tags. Is it possible to get the values that are returned by the function into the rows that are marked by XXXX to display ?
<html>
<body>
<?php
off(‘57854’);
?>
<table width="200" border="1">
<tr>
<td>XXXXX</td>
<td>XXXXX</td>
<td>XXXXX</td>
</tr>
<tr>
<td>XXXXX</td>
<td>XXXXX</td>
<td>XXXXX</td>
</tr>
<tr>
<td>XXXXX</td>
<td>XXXXX</td>
<td>XXXXX</td>
</tr>
</table>
</body>
</html>
I would like to know is there a way to display without including the html tags within the function.
Any help will be appreciated.
Thanks
Well, you cannot do looping without PHP, so your HTML has to be inside a loop. But you can return a simplified array from your function, if that helps:
The function now builds an array of the results to be returned back to the caller. Then you can just loop through that array:
This way, you can avoid having HTML inside your function, which is always a good thing to do – keep your logic separate from the presentation.