PHP coding help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tarnold4
Forum Newbie
Posts: 2
Joined: Sat Feb 14, 2015 1:37 pm

PHP coding help

Post 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>
phpRob
Forum Newbie
Posts: 9
Joined: Thu Feb 12, 2015 3:45 pm

Re: PHP coding help

Post 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.
sky2002
Forum Newbie
Posts: 4
Joined: Mon Feb 16, 2015 9:24 pm

Re: PHP coding help

Post by sky2002 »

function random image() is error

function random_image() is ok
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP coding help

Post by Celauran »

Naming aside, bear in mind that your function needs to actually return something.
tarnold4
Forum Newbie
Posts: 2
Joined: Sat Feb 14, 2015 1:37 pm

Re: PHP coding help

Post by tarnold4 »

Thanks for the help, I got the code working
Post Reply