nicob Posted October 24, 2008 Share Posted October 24, 2008 Hello I want to randomize the lines of a list. example of the list: line 1 line 2 line 3 ... My not working code :'( <?php $file = file_get_contents('index.php'); $data = explode("\n",$file); $newfile = shuffle($data); $newfile = implode("\n",$newfile); echo $newfile; ?> Where does it go wrong?? Link to comment https://forums.phpfreaks.com/topic/129931-solved-random-shuffle-array/ Share on other sites More sharing options...
feidakila Posted October 24, 2008 Share Posted October 24, 2008 the output is?? Link to comment https://forums.phpfreaks.com/topic/129931-solved-random-shuffle-array/#findComment-673573 Share on other sites More sharing options...
nicob Posted October 24, 2008 Author Share Posted October 24, 2008 the output is?? Oeps. I forgot to post this... Warning: implode() [function.implode]: Invalid arguments passed in /home/..../index.php on line 68 line 68 is $newfile = implode("\n",$newfile); Do I use the shuffle function right? Link to comment https://forums.phpfreaks.com/topic/129931-solved-random-shuffle-array/#findComment-673575 Share on other sites More sharing options...
nadeemshafi9 Posted October 24, 2008 Share Posted October 24, 2008 shuffle returns bool so you have to do it like this. <?php $file = file_get_contents('index.php'); $data = explode("\n",$file); if(shuffle($data)) { $newfile = implode("\n",$data); echo "SUCCESS !!! <br>"; echo $newfile; } else echo "Fail !!! <br>"; ?> [/CODe] Link to comment https://forums.phpfreaks.com/topic/129931-solved-random-shuffle-array/#findComment-673576 Share on other sites More sharing options...
nicob Posted October 24, 2008 Author Share Posted October 24, 2008 Thanks, nadeemshafi9! Link to comment https://forums.phpfreaks.com/topic/129931-solved-random-shuffle-array/#findComment-673577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.