ocespedes
ocespedes

Reputation: 1293

Store images in array PHP

I'm really new at php just doing some work, I want to save images in a php array and then show them in the screen, but I cannot save them or display them.

<?php 
$min = 1;
$max = 9;
$number1 = rand($min,$max);

for ($i=1 ; $i<=$number1 ; $i++){

$firstN [$i] = echo "<img src='index.jpg' border='0'>";
}   


echo $firstN [1];
?>

This is what I got , and the last line is to test it but nothing works, I google the topic but it doesn't help. Thanks in advance.

Upvotes: 0

Views: 22573

Answers (1)

OptimusCrime
OptimusCrime

Reputation: 14863

As long as index.jpg is in the same directory as your file, this should work:

<?php 
$firstN = array();
$min = 1;
$max = 9;
$number1 = rand($min, $max);
for ($i = 0; $i < $number1; $i++){
    $firstN[] = '<img src="index.jpg" border="0">';
}   

echo $firstN[0];
?>

Cleaned up the code a bit. When storing information in the array, you don't use echo and, like Mister pointed out, you had a space in the echo at the bottom of the code between the array-variable and the brackets.

Upvotes: 3

Related Questions