canabatz Posted December 10, 2010 Share Posted December 10, 2010 Hi guys! i got this code: <? $x = "abcde"; str_split($x); for ($k=0; $k<=119; $k++){ $ax = array($x[0],$x[1],$x[2],$x[3],$x[4]); shuffle($ax); $text = implode("", $ax) . ""; echo $text; echo "<br />"; } ?> if you test it you see that it is working but giving me allot of duplicates results! there is a way to ignore duplicaes while it is runing? thanx. Quote Link to comment Share on other sites More sharing options...
MMDE Posted December 10, 2010 Share Posted December 10, 2010 <?php $x='abcde'; str_split($x); $array=array(); for($k=0; $k<=119; $k++){ $ax = array($x[0],$x[1],$x[2],$x[3],$x[4]); shuffle($ax); $text=implode("", $ax) . ""; $dupe=0; foreach($array AS $row){ if($text==$row){ $dupe=1; break; } } if($dupe==0){ echo $text.'<br />'; $array[]=$text; } } ?> I think this would work! Also just to point it out, I think it can be written in 120 different ways. 5! (1*2*3*4*5) so potentially they could all be different! Quote Link to comment Share on other sites More sharing options...
canabatz Posted December 10, 2010 Author Share Posted December 10, 2010 It is working great!! im trying for two days now to solve it by myself!! i came here after i get too tired ) thanx allot man!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.