wesley Posted October 5, 2015 Share Posted October 5, 2015 Hello, I have written a function in php. If you refresh the page you see a another image, but this doesn't work. Now I see the 4 images in the browser. Can someone help me what is wrong, why didn't work mt_rand? thanks in advance. function photorandom() { $photo = array("www.google.nl" => "1.jpg", "www.bing.com" => "2.jpg", "3.jpg", "4.jpg"); $random = mt_rand(0, (count($photo)-1)); $randomImage = $photo[$random]; foreach($photo as $link => $randomImage) { echo "<a href='http://{$link}'><img src=' {$randomImage} ' width='500'></a>"; } }photorandom(); Link to comment Share on other sites More sharing options...
dsonesuk Posted October 5, 2015 Share Posted October 5, 2015 Well that generally what happens when you loop through each item in array with foreach . Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now