3v4l.org

run code in 300+ PHP versions simultaneously
html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" /> <title>Arrays from User Input</title> </head> <body> <h2>How's your weather? </h2> <?php //If form not submitted, display form. if (!isset($_POST['submit'])){ ?> <form method="post" action="yourfile.php"> <p>Please enter your information:</p> City: <input type="text" name="city" /> Month: <input type="text" name="month" /> Year: <input type="text" name="year" /> <p>Please choose the kinds of weather you experienced from the list below. <br />Choose all that apply. </p> <input type="checkbox" name="weather[]" value="sunshine" />Sunshine<br /> <input type="checkbox" name="weather[]" value="clouds" />Clouds<br /> <input type="checkbox" name="weather[]" value="rain" />Rain<br /> <input type="checkbox" name="weather[]" value="hail" />Hail<br /> <input type="checkbox" name="weather[]" value="sleet" />Sleet<br /> <input type="checkbox" name="weather[]" value="snow" />Snow<br /> <input type="checkbox" name="weather[]" value="wind" />Wind<br /> <input type="checkbox" name="weather[]" value="cold" />Cold<br /> <input type="checkbox" name="weather[]" value="heat" />Heat<br /> <p /> <input type="submit" name="submit" value="Go" /> </form> <?php //If form submitted, process input. }else{ //Retrieve the date and location information. $inputLocal = array( $_POST['city'], $_POST['month'], $_POST['year'] ); echo "In $inputLocal[0] in the month of $inputLocal[1] $inputLocal[2], you observed the following weather:<br /> <ul>"; //Save weather array into a variable. $weather = $_POST['weather']; //Iterate through the array to show what the user chose. foreach($weather as $w){ echo "<li>$w</li>\n"; } echo "</ul>"; } ?>
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.16, 8.3.0 - 8.3.3
html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" /> <title>Arrays from User Input</title> </head> <body> <h2>How's your weather? </h2> <form method="post" action="yourfile.php"> <p>Please enter your information:</p> City: <input type="text" name="city" /> Month: <input type="text" name="month" /> Year: <input type="text" name="year" /> <p>Please choose the kinds of weather you experienced from the list below. <br />Choose all that apply. </p> <input type="checkbox" name="weather[]" value="sunshine" />Sunshine<br /> <input type="checkbox" name="weather[]" value="clouds" />Clouds<br /> <input type="checkbox" name="weather[]" value="rain" />Rain<br /> <input type="checkbox" name="weather[]" value="hail" />Hail<br /> <input type="checkbox" name="weather[]" value="sleet" />Sleet<br /> <input type="checkbox" name="weather[]" value="snow" />Snow<br /> <input type="checkbox" name="weather[]" value="wind" />Wind<br /> <input type="checkbox" name="weather[]" value="cold" />Cold<br /> <input type="checkbox" name="weather[]" value="heat" />Heat<br /> <p /> <input type="submit" name="submit" value="Go" /> </form>

preferences:
262.61 ms | 408 KiB | 320 Q