Hold on... Just a moment ...
If you want to assign specific quotes for each day, that's a different situation than selecting a random quote from a list and having it remain the same for 24 hours.
Using an array, you can utilize the rand function along with a count of the total values in the array.
This will provide a single value each time it is loaded.
Additionally, there is another function called srand.
When you use srand, you establish a seed that influences the randomization process.
Alright then...
The seed determines the result of srand, which is responsible for the randomness.
You could also experiment with the shuffle function, which also relies on a seed.
Now, you'll need to determine a suitable value to serve as the seed, ensuring that this number changes every 24-hour period.
To introduce a timeline, a reference point is necessary. You might consider utilizing server time or user agent time for this purpose.
If you choose the seed '42', you will consistently get the same output from srand.
Let's illustrate this:
Imagine you have a list of 42 quotes.
Firstly, set up the array, define the seed variable, and extract the value.
$numbers = range(1,42);
$seed = floor(time()/86400);
The seed value is determined by the server's Unix timestamp, making it timezone-independent (=UTC).
To represent a daily interval, calculate based on 86400 seconds, equivalent to one day.
Randomize the array
shuffle($numbers);
and display the initial outcome.
Now let's suppose we are dealing with a list of 200 quotes:
$quoteslist= range(1,200);
$seed = floor(time()/86400);
echo $seed;
$resultado = $quoteslist;
$seed = floor(time()/86400);
shuffle($resultado);
echo $resultado[$i];
The value generated by time(), known as the timestamp, has been converted into 18846 serving as today's seed.
This seed is utilized to shuffle the list effectively.
Showcasing the first result.
// Determine the array count. Let's create a 200-quote array.
$quotes = range(1,200);
$seed = floor(time()/86400);
echo 'the seed is:'. $seed.' and it changes daily.';
echo '<hr>';
// Create another range using the same index
$quotes = range(1,200);
$resultado = $quotes;
// Display the first value without shuffling (which should be 1)
echo 'the first result of the range array : ';
echo $resultado[0];
echo '<hr>';
// Echo the shuffled result without using srand and seed, showing a different value each time
$quotes = range(1,200);
$resultado = $quotes;
shuffle($resultado);
echo 'first result of the array, randomly shuffled.. but not seeded: ';
echo $resultado[0];
echo '<br> this changes with each refresh';
echo " <hr> ";
// Generate a new random number each day utilizing a seed
$quotes = range(1,200);
$resultado = $quotes;
echo 'today: ';
$seed = floor(time()/86400);
srand($seed);
shuffle($resultado);
echo $resultado[0];
echo " * this changes daily, providing the same outcome upon reloads <hr> ";
echo '<br>';
// Today's seed
$quotes = range(1,200);
$resultado = $quotes;
echo 'the seed for today - 18846: result remains constant throughout the day, due to the specified seed : ';
srand(18846);
shuffle($resultado);
echo $resultado[0];
echo " <hr> ";
echo 'result for seed 18847 , tomorrow - consistent outcome : ';
$quotes = range(1,200);
$resultado = $quotes;
// This reflects data two days later
srand(18847);
shuffle($resultado);
echo $resultado[0];