Jump to content

[SOLVED] shuffle() gone dead please help.


redarrow

Recommended Posts

 

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);

?>

Link to comment
https://forums.phpfreaks.com/topic/144780-solved-shuffle-gone-dead-please-help/
Share on other sites

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);

?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.