Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote