tarnold4
Badges: 0
Rep:
?
#1
Report Thread starter 6 years ago
#1
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.
The whole objective is to randomly select image when webpage opens.


Code:
<html>
<head>
<title>JFQ Turnings</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<img src="jfqturnings.gif" alt="JFQ Turnings, coming soon." width="864" height="100">

<img src="table.jpg" alt="" width="864" height="567">
<?php>
function random image(){
$images = array("candlestick.jpg", "rollingpin.jpg", "table.jpg", "table2.jpg");
$random = rand(0, 3);

}
?>
</body>
</html>
0
reply
Async
Badges: 19
Rep:
?
#2
Report 6 years ago
#2
I'll post help when I'm on my laptop

Posted from TSR Mobile
0
reply
Async
Badges: 19
Rep:
?
#3
Report 6 years ago
#3
Here you go.

<?php


echo getRandomImage();




function getRandomImage()
{
$images = array("candlestick.jpg", "rollingpin.jpg", "table.jpg", "table2.jpg");
$random = rand(0, 3);
return $images[$random];
}


?>
I'm offering a free programming help desk. Drop by if you have any more programming related questions.

http://www.thestudentroom.co.uk/show...339&highlight=
0
reply
anynamewilldo
Badges: 0
Rep:
?
#4
Report 6 years ago
#4
(Original post by Async)
Here you go.



I'm offering a free programming help desk. Drop by if you have any more programming related questions.

http://www.thestudentroom.co.uk/show...339&highlight=
There's a built in function for selecting a random array

http://php.net/manual/en/function.array-rand.php
1
reply
Async
Badges: 19
Rep:
?
#5
Report 6 years ago
#5
(Original post by anynamewilldo)
There's a built in function for selecting a random array

http://php.net/manual/en/function.array-rand.php
Thanks, just learnt something new
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Do you think receiving Teacher Assessed Grades will impact your future?

I'm worried it will negatively impact me getting into university/college (218)
43.78%
I'm worried that I'm not academically prepared for the next stage in my educational journey (56)
11.24%
I'm worried it will impact my future career (37)
7.43%
I'm worried that my grades will be seen as 'lesser' because I didn't take exams (106)
21.29%
I don't think that receiving these grades will impact my future (54)
10.84%
I think that receiving these grades will affect me in another way (let us know in the discussion!) (27)
5.42%

Watched Threads

View All