php - Getting x amount of items from array -
i'm doing task in school i'm arrays , loops in php.
what i've done far make piece of code, makes array names separate text-file, , chooses random name array.
what i'd display x amount of random names. amount of names can chosen in input field, preferably or while loop (those ones know somewhat).
here code (don't think text-file necessary. if is, let me know):
<form method="post"> how many names need? <input type="number" name="amount" min="1" max="28"><br><br> <input type="submit" name="proceed" value="get name(s)"> </form> <?php $text = file_get_contents("names2t.txt"); $array = explode("\n", $text); $randnamenum = array_rand($array); $randphrase = $array[$randnamenum]; if (isset($_post["proceed"])){ echo $randphrase; } ?>
is possible i'm asking?
just add field on form , loop on :
<form method="post"> how many names need? <input type="number" name="amount" min="1" max="28"><br> how many times? <input type="number" name="repeat-count"><br> <input type="submit" name="proceed" value="get name(s)"> </form> <?php if(isset($_post['proceed'])) { for($i = 0; $i < $_post['repeat-count']; $i++) { $text = file_get_contents("names2t.txt"); $array = explode("\n", $text); $randnamenum = array_rand($array); echo $array[$randnamenum]; } } ?>
Comments
Post a Comment