I am trying to set up a random password generator function in php but this is not working for me. I get the error:
Notice: Array to string conversion in C:\xampp\htdocs\php-testing\index.php on line 12
Array
What am I doing wrong?
<?php
function pwGenerator($len = 10) {
$charRange = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789!@#$%^&*()";
$pw = array();
$length = strlen($charRange);
for ($x = 0; $x < $len; $x++) {
$n = rand(0, $length);
$pw[] = $charRange[$n];
}
return $pw;
}
echo pwGenerator();
echo ...that array. For an echo it would have to be a string. So do this:return implode('', $pw);