【问题标题】:Random Word And change the layout with PHP随机单词并使用 PHP 更改布局
【发布时间】:2021-10-20 14:06:19
【问题描述】:

我有 3 个词:(书、帮助、空气)

我想让这3个词以不同的模式显示

Example :
book help air
book air help
help air book
air book help
....

【问题讨论】:

    标签: php jquery random numbers word


    【解决方案1】:

    首先将你的单词设置为数组

    $array = ['book', 'help', 'air'];
    
    echo random_string_from_array( $array, 10);
    
    
    // Function For string from words array randomization 
       
    // $array is array of words, $n is number of times of randomization of words
        function random_string_from_array( $array, $n)
        {
    
            $my_str = '';
            
            for( $i == 1; $i <= $n; $i++ )
            {
                
              shuffle($array);
              
              $my_str .= implode(" ",$array);
              $my_str .= "<br>";
              
            }
        
            return $my_str;
        }
        
        
    

    【讨论】:

    【解决方案2】:

    你可以使用函数:array_randhttps://www.php.net/manual/en/function.array-rand.php

    $array = ['book', 'help', 'air'];
    
    echo array_rand($array);
    

    【讨论】:

      猜你喜欢
      • 2013-10-02
      • 1970-01-01
      • 2012-03-16
      • 1970-01-01
      • 1970-01-01
      • 2021-05-23
      • 2014-02-06
      • 1970-01-01
      • 2018-11-21
      相关资源
      最近更新 更多