1

How to, Every minute changing and taking data from an array that follows a random path each day.

In fact every single minute in a day will change a key. And every day will follow a random path, not the same thing.

I tried something below, "Of course this is completely exemplary"

$pattern_1 = array(1,0,2,4,3);
$pattern_2 = array(0,4,1,3,2);
$pattern_3 = array(2,1,3,0,4);
...
$pattern_31 = array(0,4,3,1,2);

$key = array("key1","key2","key3","key4","key5");


$pattern = array($patternt_1, $patternt_2, $patternt_3, ... $patternt_31);


$day = date('j'); // 0 - 31

$hour = date('G'); // 0 - 24


echo $key[$pattern[$day][$hour]];

2 Answers2

0

You can use rand function. For example

$keys = ["key1", "key2", ... "keyn"];
echo $keys[rand(0, count($keys) - 1)];

UPD

If you just want to generate random string please take a look on this answer

Vitalii
  • 1,137
  • 14
  • 25
-1

You don't tell us for which use you need an ever changing code, but why don't you simply use a proper random function as mt_rand() to generate a random code?

Then, if you need it to remain the same for one minute, you can save it in a php file with its timestamp, and then you always load it, check if a minute has passed and generate a new one if that is the case, then save it back:

$stamp=time();
$key=mt_rand(0,4);

include("store.php");

if (time()-$stamp>60):
   $stamp=time();
   $key=mt_rand(0,4);
endif;

file_put_contents("store.php","<"."?php $"."stamp=".$stamp.";$"."key=".$key.";");
Shores
  • 95
  • 7