独特的随机字符生成器

时间:2015-06-04 20:49:30

标签: php arrays random

PHP初学者在这里。以下代码是否会按照我的正确说法进行操作?

//Random code generator
function random_string_func() {
    //Hash generator
    $generated_hash = md5(uniqid(rand()));

    //get all existing hashes and store them into an array
    $existing_hashes = FrmEntryMeta::get_entry_metas_for_field(198, '', '', array()); //change 198 to the ID of the date field

    //Check if the newly generated hash exists in WP database
    if(in_array($generated_hash, $existing_hashes)){ 
        //If yes, generate a new hash
        $generated_hash = md5(uniqid(rand()));
    }
    return $generated_hash;
}
add_shortcode( 'random_string', 'random_string_func' );

0 个答案:

没有答案