How do I make and display an array of images (red.png, yellow.png, green.png) in
ID: 3675282 • Letter: H
Question
How do I make and display an array of images (red.png, yellow.png, green.png) in php? Here is my code so far, but it only shows the table border and background etc. The color files are in the same directory as the create_stoplight.php file. Thank you.
<?php
function create_table2($data, $border=1, $cellpadding=4, $cellspacing=4, $bgcolor="black" )
{
echo "<table border="".$border."" cellpadding="".$cellpadding.""
cellspacing="".$cellspacing."" bgcolor="".$bgcolor."">";
reset($data);
$value = current($data);
while ($value)
{
echo "<tr><td>".$value."</td></tr> ";
$value = next($data);
}
echo "</table>";
}
$my_array = array('red.jpg','yellow.jpg','green.jpg');
create_table2($my_array, 3, 8, 8);
?>
Explanation / Answer
Change the content of while loop as:
while ($value)
{
echo '<tr><td> <img src="'.$value.'"></img></td></tr>';
$value = next($data);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.