Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Array - Remove Comma, If else statement
    text
    copied!<p>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.</p> <p>My code:</p> <pre><code>&lt;?php $imagearrdisplay = ",8,7,22,"; $displayitem = explode(",", $imagearrdisplay); for($i = 0; $i &lt; count($displayitem); $i++){ echo " &lt;div class='banner'&gt;&lt;img src='/images/transitions/$displayitem[$i].jpg' /&gt;&lt;/div&gt; Count: $i = $displayitem[$i] "; } ?&gt; </code></pre> <p>It currently returns a result of:</p> <pre><code>&lt;div class='banner'&gt;&lt;img src='/images/transitions/.jpg' /&gt;&lt;/div&gt; Count: 0 = &lt;div class='banner'&gt;&lt;img src='/images/transitions/8.jpg' /&gt;&lt;/div&gt; Count: 1 = 8 &lt;div class='banner'&gt;&lt;img src='/images/transitions/7.jpg' /&gt;&lt;/div&gt; Count: 2 = 7 &lt;div class='banner'&gt;&lt;img src='/images/transitions/22.jpg' /&gt;&lt;/div&gt; Count: 3 = 22 &lt;div class='banner'&gt;&lt;img src='/images/transitions/.jpg' /&gt;&lt;/div&gt; Count: 4 = </code></pre> <p>What I would like to achieve is the following:</p> <ol> <li><p>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.</p></li> <li><p>Randomise the results of the array</p></li> <li><p>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.</p></li> </ol> <p>To be able to then produce an outcome that looks like:</p> <pre><code>&lt;div class='firstbanner'&gt;&lt;img src='/images/transitions/22.jpg' /&gt;&lt;/div&gt; &lt;div class='banner'&gt;&lt;img src='/images/transitions/7.jpg' /&gt;&lt;/div&gt; &lt;div class='banner'&gt;&lt;img src='/images/transitions/8.jpg' /&gt;&lt;/div </code></pre> <p>I know it's possible, though struggling through the maze of tutes out there. Any help would be really appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload