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
https://forums.phpfreaks.com/topic/14940-need-help/#findComment-59931
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
https://forums.phpfreaks.com/topic/14940-need-help/#findComment-59936
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
https://forums.phpfreaks.com/topic/14940-need-help/#findComment-59964
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.