index.php
<?php
$fileName = 'output_file.php';
$content = '';
for ($i = 0; $i < 10; $i++) {
$var1 = "variable: 1 value is: " . $i;
$var2 = "variable: 2 value is: " . $i * 10;
/* OR write: extract($vars); if you have additional parameters. */
ob_start();
include $fileName;
$content .= ob_get_contents();
ob_end_clean();
}
echo $content;?>
output_file.php
<div>
<div>var1 == <?php echo $var1; ?></div>
<div>var2 == <?php echo $var2; ?></div>
</div>
<br/><br/>
And finally the output is:
<div>
<div>var1 == variable: 1 value is: 0</div>
<div>var2 == variable: 2 value is: 0</div>
</div>
<br/><br/>
<div>
<div>var1 == variable: 1 value is: 1</div>
<div>var2 == variable: 2 value is: 10</div>
</div>
<br/><br/>
<div>
<div>var1 == variable: 1 value is: 2</div>
<div>var2 == variable: 2 value is: 20</div>
</div>
<br/><br/>
<div>
<div>var1 == variable: 1 value is: 3</div>
<div>var2 == variable: 2 value is: 30</div>
</div>
<br/><br/>
<div>
<div>var1 == variable: 1 value is: 4</div>
<div>var2 == variable: 2 value is: 40</div>
</div>
<br/><br/>
<div>
<div>var1 == variable: 1 value is: 5</div>
<div>var2 == variable: 2 value is: 50</div>
</div>
<br/>
<br/>
<div>
<div>var1 == variable: 1 value is: 6</div>
<div>var2 == variable: 2 value is: 60</div>
</div>
<br/><br/>
<div>
<div>var1 == variable: 1 value is: 7</div>
<div>var2 == variable: 2 value is: 70</div>
</div>
<br/><br/>
<div>
<div>var1 == variable: 1 value is: 8</div>
<div>var2 == variable: 2 value is: 80</div>
</div>
<br/><br/>
<div>
<div>var1 == variable: 1 value is: 9</div>
<div>var2 == variable: 2 value is: 90</div>
</div>
<br/><br/>
No comments:
Post a Comment