Search code examples
phparraysexplodeimplode

Show each value in a PHP array as an image in HTML


I have a script to upload multiple images. After upload this is the logic:

if(isset($_POST['submit'])){

    $value = $_POST['uploaded_image_name'];
    //print_r(array_values ($value));
    echo "</br>";
    $juntos = implode("-",$value); // joga no db tipo separados por - 1591455823.jpg-1591455824.jpg
    echo $juntos;
    print_r (explode("-",$juntos)); //volta o array 
}

This code returns to me something like:

1591456130.jpg-1591456132.jpg 

and the explode

print_r (explode("-",$juntos));

returns:

Array ( [0] => 1591456130.jpg [1] => 1591456132.jpg )

The question is how to get these array values use them as the source for HTML images? Something like this:

echo '<img src="1591456130.jpg">';
echo '<img src="1591456132.jpg">';

Solution

  • To iterate the array and print the contents as a list in the browser.

    foreach($value as $img){
         print "<img src='$img' >";
    }