The program knows how many letters there are and how many arrays to add.
Below I commented more on the little program.
<?php
$string = "ALF"; // Database String
$length = strlen($string); // Length of String from database.
/ The $length variable signals when to stop this for loop. The $i variable will be incremented each time the value in $i is less than the $length value. This will make it so the user does not have to worry about creating more arrays. The comment below describes some of the purposes of each function used. /
for($i = 0; $i < $length; $i++)
{
$image[$i] = strtolower($string[$i]). ".gif";
/ You'll have to recall that strings are also in fact arrays of letters themselves. So, the line above takes the first array [0] of $string which is "A" and the strtolower() function makes it lowercase. Afterwards the "." I used adds the text ".gif" onto the lowercase "a". All this data is then assigned into $image[$i]. Remember $i increments after every use. Using the example above of the first letter in the $string[0], $i would equal zero. Thus $image[$i] is the equivalent of $image[0]. However, when it loops around again $i is incremented one value. So $image[$i] would be then equivalent to $image[1] and the $string[$i] value would have the value "L".
/
}
print("$image[0], $image[1], $image[2]");
?>
If you require a print out of consecutive image tags afterwards then, just add these lines of code:
$total = count($image);
for($j = 0; $j < $total; $j++)
{
print("<img src=$image[$j]>");
}
Instead of:
print("$image[0], $image[1], $image[2]");
That should give you the desired results.