0

I am using the code as under but always getting 0 value means the same folder

$random_folder=array("folder1","folder2","folder3");
$folder=$random_folder[rand(0,count($random_folder)-1)];

Getting folder1 always.. What's wrong??
Please Help.......

Edited by kirtan_thakkar: n/a

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by msm_eg
0

Hi kirtan_thakkar,

There's nothing wrong with your code. The reason your getting all folder1 is that there is also 3 items on your array. And its randomized, so maybe "0" today could have been your lucky number. :)

Tip:
Keep refreshing the page and let's see it doesn't change.

Regards,
Al

0

Hi kirtan_thakkar,

There's nothing wrong with your code. The reason your getting all folder1 is that there is also 3 items on your array. And its randomized, so maybe "0" today could have been your lucky number. :)

Tip:
Keep refreshing the page and let's see it doesn't change.

Regards,
Al

I have tried more than 50 time but getting on folder1...

0

Hi,

Can you post the whole code please?

I tried myself, it does change.

Regards,
Al

$random_folder=array("folder1","folder2","folder3");

$folder=$random_folder[rand(0,count($random_folder)-1)];

if($folder="folder1")
	include("folder1.php");
elseif($folder="folder2")
	include("folder2.php");
else
	include("folder3.php");

$random_file=$file[rand(0,count($file)-1)];
$filename=$folder."/".$random_file.".txt";
$handle=fopen($filename,"r");
$contents=fread($handle,filesize($filename));
echo($contents);

And that include in if includes that php file where i have stored the arrays for that folder and the array name is file.
I am getting files from only folder1..

Edited by kirtan_thakkar: n/a

0

Hi,

Try replacing this lines,

$folder="folder1"

with

$folder=="folder1"

Also,

elseif($author_folder="folder2")

with

elseif($folder=="folder2")

Edited by ivatanako: n/a

0

Hi,

Try replacing this lines,

$folder="folder1"

with

$folder=="folder1"

Also,

elseif($author_folder="folder2")

with

elseif($folder=="folder2")

Hey thanks...
It has worked.. I have tried 4 hours to find it and you have solved in a minut..

0

try to caluclate it outside the array do like this.

$folderarrayNumb = count($random_folder)-1;
$myrand = rand(0,$folderarrayNumb);
$folder=$random_folder[$myrand];

Edited by msm_eg: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.