Volcano T. answered 05/28/19
Tutor
New to Wyzant
Programming / SysAdmin / DBA
the function was okay, just how you call the function.
as your function has a return value, you need to receive that return value and print that out.
your variable name $randstring was inside the function and when you need it in the main programme, use another one.
function RandomString()
{
$charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randstring = '';
for ($i = 0; $i < 10; $i++)
{
$randstring .= $charset[rand(0, strlen($charset))];
}
return $randstring;
}
$str = RandomString();
echo $str;