I have the maximum number of warnings during PHP development. How can I
get rid of these warnings without turning them off in PHP?
Here's the code I have:
<form method="POST" action="eat.php ">
<select name="lunch[ ]" multiple>
<option value="pork">BB Q Pork Bun</option>
<option value="chicken" >Chicken Bun</option>
<option value="lotus">L otus Seed Bun</option>
<option value="bean">Be an Paste Bun</option>
<option value="nest">Bi rd-Nest Bun</option>
</select>
<input type="submit" name="submit">
</form>
Selected buns: <br/>
<?php
foreach ($_POST['lunch'] as $choice) {
print "You want a $choice bun. <br/>";
}
?>
And I get: Warning: Invalid argument supplied for foreach() in
C:\lighttpd\htd ocs\index.php on line 17
Is there a way to give the 'lunch' variable a default value if
undefined?
Thank you.
get rid of these warnings without turning them off in PHP?
Here's the code I have:
<form method="POST" action="eat.php ">
<select name="lunch[ ]" multiple>
<option value="pork">BB Q Pork Bun</option>
<option value="chicken" >Chicken Bun</option>
<option value="lotus">L otus Seed Bun</option>
<option value="bean">Be an Paste Bun</option>
<option value="nest">Bi rd-Nest Bun</option>
</select>
<input type="submit" name="submit">
</form>
Selected buns: <br/>
<?php
foreach ($_POST['lunch'] as $choice) {
print "You want a $choice bun. <br/>";
}
?>
And I get: Warning: Invalid argument supplied for foreach() in
C:\lighttpd\htd ocs\index.php on line 17
Is there a way to give the 'lunch' variable a default value if
undefined?
Thank you.
Comment