0

すべてのテキストボックスの応答をresults.phpに投稿してから、表示する応答の1つをランダムに選択したいと思います。

フォーム:

<form action="results.php" method="post">
<input maxlength="30" name="friend[]" size="30" type="text" placeholder="Enter an option" />
<input maxlength="30" name="friend[]" size="30" type="text" placeholder="Enter an option" />
<input maxlength="30" name="friend[]" size="30" type="text" placeholder="Enter an option" />
<input maxlength="30" name="friend[]" size="30" type="text" placeholder="Enter an option" />
<input type="submit" value="Submit" />

phpの内容(明らかに間違っていますが、このようなものですか?)

foreach ($_POST['friend'] as $value) {          
    if ($value) {
      echo mt_rand($value);
    }
}
4

2 に答える 2

1

あなたが使用することができますarray_rand

$random_input = $_POST['friend'][array_rand($_POST['friend'])];
于 2012-10-08T22:32:20.450 に答える
0
echo $_POST['friend'][ rand(0, count($_POST['friend']) - 1) ];
于 2012-10-08T22:32:42.777 に答える