Jump to content

choose randomly


11Tami

Recommended Posts

Hello, how would I get this to choose a line of text randomly instead of in order so it doesn't pick the same one twice in a row? Please let me know, thanks very much.

 

<?php 
$maximum=3; 
$a = (isset($_COOKIE['e']) && intval($_COOKIE['e']) < $maximum)? intval($_COOKIE['e'])+1 : 1; 
setcookie("e", $a, time()+60*60*24*180); 
$text[1] = "test1"; 
$text[2] = "test2"; 
$text[3] = "test3";
php echo "$text[$a]";
?> 

Link to comment
https://forums.phpfreaks.com/topic/69630-choose-randomly/
Share on other sites

Maybe there's a way to get it to output a number from the array first like 1, 2, or 3 and then put that into the random function? Anyone know how to get it to output an array number? Or maybe there is an easier way.

 

I was missing the whole code, here's all of it.

 

<?php 
$maximum=3; 
$a = (isset($_COOKIE['e']) && intval($_COOKIE['e']) < $maximum)? intval($_COOKIE['e'])+1 : 1; 
setcookie("e", $a, time()+60*60*24*180); 
$text = Array();
$text[1] = "test1"; 
$text[2] = "test2"; 
$text[3] = "test3";
php echo "$text[$a]";
?> 

Link to comment
https://forums.phpfreaks.com/topic/69630-choose-randomly/#findComment-349882
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.