PHP array_rand not displaying results randomly

Viewed 17

The following is not working, why ?

    <?php
$divs = array('<li><span><i class="wo-themeicon"><img src="images/theme-icon/img-01.png" alt="img description"></i>Fire-resistant</span></li>',
              '<li><span><i class="wo-themeicon"><img src="images/theme-icon/img-02.png" alt="img description"></i>Moisture-resistant</span></li>',
              '<li><span><i class="wo-themeicon"><img src="images/theme-icon/img-03.png" alt="img description"></i>Impact-resistant</span></li>',
              '<li><span><i class="wo-themeicon"><img src="images/theme-icon/img-04.png" alt="img description"></i>Abuse-resistant</span></li>');

// Array with 2 random keys from $divs
$randKeys = array_rand($divs, 4);

                                    echo $divs[$randKeys[0]]; // First random div
                                    echo $divs[$randKeys[1]]; // Second random div
                                    echo $divs[$randKeys[2]]; // Third random div
                                    echo $divs[$randKeys[3]]; // Fourth random div
                                    ?>

It just displays the 4 array values, not displaying randomly. Results seems to be same always. I was expecting different sorting each time.

0 Answers
Related