Im very new to php, I wanted to see if anyone could help me with the following. I have to take a function, along with the count function, to randomly select one of the array values. Use the return keyword to return this value and end the function. The value returned should be one of the provided file names.
When you ask for help like this it seems like you aren’t asking for help to solve a problem, it seems like you’re asking for someone to code it for you.
If you provide the code you have and problems/errors with it then it’s much easier to push yourself in the right direction.
This is the code i have so far
[code]
JFQ Turnings}
?>
As I read it they want you to pass the array of images into the function.
[php]function randomImage($images) { … }
$images = array(“candlestick.jpg”, “rollingpin.jpg”, “table.jpg”, “table2.jpg”);
echo randomImage($images);[/php]
[size=9pt]"…" is just a placeholder for content, note that the name should be without spaces[/size]
[hr]
You are correct in beeing able to use the rand function, but you should swap out the static length (3), with the count of values in the array (hint: “along with the count function”).
[hr]
With the random number generated you can just return that key of the array. Remember that the array keys start with 0, so if you have 4 array values you can not select $array[4], $array[3] is the last (fourth) value.
Thanks for the help, the main thing this has to do is randomly show an image, when i load a webpage
Let us know if you run into any other problems