Jump to content

Arrays


zero_ZX

Recommended Posts

Hi,

I'm having some trouble trying to generate my random string for a name.

This is my code:

<?PHP
function rand_string( $length ) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";	

$size = strlen( $chars );
for( $i = 0; $i < $length; $i++ ) {
	$str .= $chars[ rand( 0, $size - 1 ) ];
}

return $str;
}

$salt_string = rand_string( 5 );

$test = "1234";

echo "salt_string = $salt_string";
echo "<br>";
echo "test = 1234";
echo "<br>";
$array = array('$test', '$salt_string');
echo "<br>";
echo "array = $array";
echo "<br>";
$imploded = implode($array);
echo "<br>";
echo "imploded = $imploded"; 

?>

 

And it returns:

 

salt_string = 8pbAe

test = 1234

 

array = Array

 

imploded = $test$salt_string

 

I don't understand why my imploded variable is not 12348pbAe

Link to comment
Share on other sites

Ah, thanks a lot :D

 

For those of you who want working code:

<?PHP
function rand_string( $length ) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";	

$size = strlen( $chars );
for( $i = 0; $i < $length; $i++ ) {
	$str .= $chars[ rand( 0, $size - 1 ) ];
}

return $str;
}

$salt_string = rand_string( 5 );

$test = "1234";

echo "salt_string = $salt_string";
echo "<br>";
echo "test = 1234";
echo "<br>";
$array = array($test, $salt_string);
echo "<br>";
echo "array = $array";
echo "<br>";
$imploded = implode($array);
echo "<br>";
echo "imploded = $imploded"; 

?>

Link to comment
Share on other sites

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.