Jump to content

Need help!


Gruzin

Recommended Posts

Well, you didn't post all of your code, but the following should work:

[code=php:0]
<?php
$imageArr = array();
$imageArr[] = "/pics/fish.jpg";
$imageArr[] = "/pics/robo.jpg";
?>
[/code]
There is no need to explicitly assign numeric keys.

Oh yeah, and note that you aren't actually storing the images in array, but the string location.
Link to comment
Share on other sites

It doesn't work, here is the code:

<?
//array to hold the pictures
$imageArr= array();
$imageArr[1] = "/pics/fish.jpg";
$imageArr[2] = "/pics/robo.jpg";

//randomization
$imageShow = rand(1, count ($imageArr));?>

//to show the pictures in random way
<? echo $imageArr[$imageShow]; ?>
Link to comment
Share on other sites

Use array_rand().

[code=php:0]
<?php
//array to hold the pictures
$imageArr= array();
$imageArr[1] = "/pics/fish.jpg";
$imageArr[2] = "/pics/robo.jpg";
$rand_keys = array_rand($input);
echo $imageArr[$rand_keys[0]];
?>
[/code]
That will randomize your array.
Link to comment
Share on other sites

I'm sorry.  I had a different var name:
[code=php:0]
<?php
//array to hold the pictures
$imageArr= array();
$imageArr[1] = "/pics/fish.jpg";
$imageArr[2] = "/pics/robo.jpg";
$rand_keys = array_rand($imageArr);
echo $imageArr[$rand_keys[0]];
?>
[/code]
Link to comment
Share on other sites

Come on now Gruzin! 
[code=php:0]
<?php
//array to hold the pictures
$imageArr= array();
$imageArr[1] = "/pics/fish.jpg";
$imageArr[2] = "/pics/robo.jpg";
$rand_keys = array_rand($imageArr);
echo '<img src="'.$imageArr[$rand_keys].'" />';
?>
[/code]
Link to comment
Share on other sites

When using abs paths, you need to specify from the web root.  If your web root is /html then do this:

[code=php:0]
<?php
//array to hold the pictures
$imageArr= array();
$imageArr[1] = "/test/pics/fish.jpg";
$imageArr[2] = "/test/pics/robo.jpg";
$rand_keys = array_rand($imageArr);
echo '<img src="'.$imageArr[$rand_keys].'" />';
?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.