Jump to content

Problems with foreach and form-select


janek211

Recommended Posts

I am beginner, I am trying to use foreach to display some things in a select, but its always showing the highest value, why? Please help me

<html>

<head>

<body>

<form action="form5.php" method="post">

<?

$days= array (1=>'m','n','k');

echo '<select name="day">';

 

foreach ($days as $key => $value);

{echo "<option value=\"$key\">$value</option>";}

echo '</select>';

?>

</form>

<body>

<head>

<html>

Link to comment
https://forums.phpfreaks.com/topic/118007-problems-with-foreach-and-form-select/
Share on other sites

remove ; in foreach line

<html>
<head>
<body>
<form action="form5.php" method="post">
<?
$days= array (1=>'m','n','k');
echo '<select name="day">';

foreach ($days as $key => $value) //; <-- remove this
{echo "<option value=\"$key\">$value</option>";}
echo '</select>';
?>
</form>
<body>
<head>
<html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.