draj840143 2015-12-10 23:01 采纳率: 100%
浏览 28
已采纳

从多个单词的字符串中打印随机字符串

I am new to php and trying out some different things. I got a problem with printing a random value from a string from multiply values.

    $list = "the weather is beautiful tonight".
    $random = one random value from $list, for example "beautiful" or "is"

Is there any simple way to get this done? Thanks!

  • 写回答

2条回答 默认 最新

  • douzhi4830 2015-12-10 23:04
    关注
    // First, split the string on spaces to get individual words
    $arg = explode(' ',"the weather is beautiful tonight");
    
    // Shuffle the order of the words
    shuffle($arg);
    
    // Display the first word of the shuffled array
    print $arg[0];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?