簡體   English   中英

在 php 中執行 echo 或 class x 次

[英]Execute an echo or class x times in php

我遇到的問題是,我想像 $intcount 的數量一樣經常回顯類 $password。 你能告訴我我會怎么做嗎? 如果 $intcount 是 4 則我回顯 4 個隨機單詞,如果是 5 則回顯 5 個單詞等等。

<?php

$csv = array_map('str_getcsv', file('gen.csv'));
$count = $_GET['count'];
$intcount = (int)$count;
$min = 0;
$max = 4;
$rand = mt_rand( $min , $max );

$out = $csv[$rand][$rand];

$password = $out;

// var_dump($count);
// var_dump($intcount);
// 
// echo $count . "\n <br>";
// echo $password * $intcount;
// 
// for ($i=0; $i < $intcount ; $i++) {
//     echo $password;
// }

?>

注釋代碼不一定要保留。

謝謝 :)

您需要在循環內創建$rand ,如:

$csv = array_map('str_getcsv', file('gen.csv'));
$count = $_GET['count'];
$intcount = (int)$count;
$min = 0;
$max = 4;

for ($i=0; $i < $intcount ; $i++)
{
    $rand = mt_rand($min, $max);
    $password = $csv[$rand][$rand];
    echo $password;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM