Page 1 of 1

PHP coding help

Posted: Sat Feb 14, 2015 1:42 pm
by tarnold4
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.
***** Please use the PHP Code tag around source code *****

Code: Select all

<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">
  <br /><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>

Re: PHP coding help

Posted: Sat Feb 14, 2015 1:50 pm
by phpRob
The php docs on arrays reveals the function you need. The url is: http://php.net/manual/en/ref.array.php

The function is array_rand. I will resist the temptation to do the coding for you. Let me know if you can't get it to work as desired.

Re: PHP coding help

Posted: Tue Feb 17, 2015 7:32 pm
by sky2002
function random image() is error

function random_image() is ok

Re: PHP coding help

Posted: Tue Feb 17, 2015 8:07 pm
by Celauran
Naming aside, bear in mind that your function needs to actually return something.

Re: PHP coding help

Posted: Wed Feb 18, 2015 6:16 am
by tarnold4
Thanks for the help, I got the code working