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