Thread: Random Text
View Single Post
Old 05-07-2008, 12:07 PM   #10 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

sketch, your first code snippet has an off-by-one error related to the $cnt variable. It needs to be count()-1 for the loops and calls to rand else you'll get "Undefined offset" notices.

Also, what's the harm in using something like the following instead of the longer, looping code snippet?
PHP Code:
$words 'I took my dog for a walk';
$shuffled explode(' '$words);
shuffle($shuffled);
echo 
implode(' '$shuffled); 
Salathe is offline  
Reply With Quote