redarrow Posted February 11, 2009 Share Posted February 11, 2009 advance thank you . why my shuffle not working please. debugged every think nothing wrong. <?php function user_password(){ $passwords[]="0123456789abcdefghijklmnopqurstuvwxyz"; shuffle($passwords); $password=substr($passwords[0],0,7); return $password; } echo user_password($password); ?> Quote Link to comment https://forums.phpfreaks.com/topic/144780-solved-shuffle-gone-dead-please-help/ Share on other sites More sharing options...
rhodesa Posted February 11, 2009 Share Posted February 11, 2009 shuffle is for arrays....you have an array with one element...you want to shuffle a string...use this instead: <?php function user_password(){ $passwords = "0123456789abcdefghijklmnopqurstuvwxyz"; $password=substr(str_shuffle($passwords),0,7); return $password; } echo user_password($password); ?> Quote Link to comment https://forums.phpfreaks.com/topic/144780-solved-shuffle-gone-dead-please-help/#findComment-759719 Share on other sites More sharing options...
Maq Posted February 11, 2009 Share Posted February 11, 2009 Shuffle randomizes the elements in the array. You only have 1. There's nothing else to shuffle... Quote Link to comment https://forums.phpfreaks.com/topic/144780-solved-shuffle-gone-dead-please-help/#findComment-759720 Share on other sites More sharing options...
printf Posted February 11, 2009 Share Posted February 11, 2009 shuffle takes an array of key names => key values, you're giving it a single key_name => key_value, so there is nothing to shuffle... Also I really hope you are not planing to generate passwords that way! Quote Link to comment https://forums.phpfreaks.com/topic/144780-solved-shuffle-gone-dead-please-help/#findComment-759727 Share on other sites More sharing options...
rhodesa Posted February 11, 2009 Share Posted February 11, 2009 shuffle takes an array of key names => key values, you're giving it a single key_name => key_value, so there is nothing to shuffle... Also I really hope you are not planing to generate passwords that way! printf makes a good point....this isn't a good way to make a password. limiting the possible lets to only 1 of each letter reduces the number of possibilities Quote Link to comment https://forums.phpfreaks.com/topic/144780-solved-shuffle-gone-dead-please-help/#findComment-759733 Share on other sites More sharing options...
redarrow Posted February 11, 2009 Author Share Posted February 11, 2009 thank u. Quote Link to comment https://forums.phpfreaks.com/topic/144780-solved-shuffle-gone-dead-please-help/#findComment-759772 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.