I have a select that Id e to fill the options with a array. I'm not quite getting how to do it. Currently I'm trying this:
<html>
<head>
<title>test</title>
<body>
<select>
<?php $theArr = array("Home", "Events", "Bio", "Contact");?>
<?php foreach ($theArr as $menu_option){ ?>
<option><?php $menu_option; ?></option>
<?php } ?>
</select>
</body>
</html>
but all I'm getting is a empty drop down, not sure what I'm doing wrong
You need to write echo
for display output. Change your drop down as below:
<select>
<?php $theArr = array("Home", "Events", "Bio", "Contact");?>
<?php foreach ($theArr as $menu_option){ ?>
<option><?php echo $menu_option; ?></option>
<?php } ?>
</select>
You are not outputting anything
<html>
<head>
<title>test</title>
</head> <!-- also close your head -->
<body>
<select>
<?php $theArr = array("Home", "Events", "Bio", "Contact");?>
<?php foreach ($theArr as $menu_option){ ?>
<option><?php echo $menu_option; ?></option>
<?php } ?>
</select>
</body>
</html>
You need to add echo
to your code, or print_r
to make sure that the results are being printed. OR you can simply use <?=$menu_options;?>
You are missing echo statement
enter code here
<html>
<head>
<title>test</title>
</head>
<body>
<select>
<?php $theArr = array("Home", "Events", "Bio", "Contact");?>
<?php foreach ($theArr as $menu_option){ ?>
<option><?php echo $menu_option; ?></option>
<?php } ?>
</select>
</body>
You are missing an echo
:)
<select>
<?php $theArr = array("Home", "Events", "Bio", "Contact");?>
<?php foreach ($theArr as $menu_option): ?>
<option><?php echo $menu_option; ?></option>
<?php endforeach;?>
</select>
I also change your {}
to much easier to read.