Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.