Forum Moderators: coopster
$a[example] = explode("+", $a[asdf]);
shuffle($a[example]);
$a[example2] = implode("+", $a[example]);
$a[example2] = str_replace("+", ' and ', $a[example2]);
But it seems as though 50% of the time the exploded sequence of numbers ends up in exactly the same sequence! Not much use. Is there any coding that will explode the sequence and shuffle it but ensure that it doesn't suffle it back into it's original sequence?
If you can, don't worry about it, just relax and learn to love shuffle().
If it wasn't a worry/problem then I wouldn't be asking about it. Thanks anyway for the sentiment, I take it that means you don't know of a way around it?
The problem is that I wanted to shuffle the strings so I used shuffle. It kind of defeats what I'm doing (sort of a lottery/raffle/gaming thing) if the numbers end up in the same order.
Let me be more explicit. It's nothing to worry about. The apparent pattern is an illusion.
I didn't find that any clearer. What I'm really interested in is actual, factual coding (if it exists) not a theological debate about the eternal nature and mythical buddhist perceptions of php ...
... how can the order re-arranging itself back into its original order be an "illusion"?
coopster - it does work for me too, but not every time. A large part of the time the string ends up right back where it started, which is not what I want. The strings vary from 3 numbers to 10 and the number of variables doesn't seem to make a difference.
do
{
$a[example] = explode("+", $a[asdf]);
$temp = $a[example];
shuffle($temp);
$a[example2] = implode("+", $temp);
}while($a[example] == $a[example2])
$a[example2] = str_replace("+", ' and ', $a[example2]);
You would certainly get it changed this time, as I think that's what you want.
PS. Remeber to put some limit into the loop as not to get caught in endless repeating.