我正在尝试创建一个应该包含 30 个字符的随机字符串。但有时它也会创建 28 个字符。如何解决问题?我的代码是这样的:
function random_string(){
$character_set_array = array( );
$character_set_array[ ] = array( 'count' => 15, 'characters' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ' );
$character_set_array[ ] = array( 'count' => 6, 'characters' => '0123456789' );
$character_set_array[ ] = array( 'count' => 9, 'characters' => '!@#$%^&+_|~-=\{}[]:?/' );
$temp_array = array( );
foreach ( $character_set_array as $character_set )
{
for ( $i = 0; $i < $character_set[ 'count' ]; $i++ )
{
$temp_array[ ] = $character_set[ 'characters' ][ rand( 0, strlen( $character_set[ 'characters' ] ) - 1 ) ];
}
}
shuffle( $temp_array );
return implode( '', $temp_array );
}
请帮我。