I am relatively new to arrays, and struggling with the amount of information out there to solve my problem succinctly. This is as far as I have progressed.
My code:
<?php
$imagearrdisplay = ",8,7,22,";
$displayitem = explode(",", $imagearrdisplay);
for($i = 0; $i < count($displayitem); $i++){
echo "
<div class='banner'><img src='/images/transitions/$displayitem[$i].jpg' /></div>
Count: $i = $displayitem[$i] ";
}
?>
It currently returns a result of:
<div class='banner'><img src='/images/transitions/.jpg' /></div>
Count: 0 =
<div class='banner'><img src='/images/transitions/8.jpg' /></div>
Count: 1 = 8
<div class='banner'><img src='/images/transitions/7.jpg' /></div>
Count: 2 = 7
<div class='banner'><img src='/images/transitions/22.jpg' /></div>
Count: 3 = 22
<div class='banner'><img src='/images/transitions/.jpg' /></div>
Count: 4 =
What I would like to achieve is the following:
To remove the first and last comma within the imagearraydisplay when it explodes so that I do not end up with a blank image at the beginning and end.
Randomise the results of the array
Perform an if / else function to find the [0] and adjust the first result so that I can use css to style the image accordingly.
To be able to then produce an outcome that looks like:
<div class='firstbanner'><img src='/images/transitions/22.jpg' /></div>
<div class='banner'><img src='/images/transitions/7.jpg' /></div>
<div class='banner'><img src='/images/transitions/8.jpg' /></div
I know it's possible, though struggling through the maze of tutes out there. Any help would be really appreciated.