Posted by Chuck Anderson on 10/29/87 11:56
Jerry Stuckle wrote:
> Lenard Redwood wrote:
>
>> Manish wrote:
>>
>>
>>> <?php
>>>
>>> if(is_array($_POST['lunch']) && count($_POST['lunch'])) {
>>> foreach ($_POST['lunch'] as $choice) {
>>> print "You want a $choice bun. <br/>";
>>> }
>>> }
>>>
>>> ?>
>>>
>> Thank you. Now I get this error:
>>
>> Notice: Undefined index: lunch in C:\lighttpd\htdocs\index.php on line
>> 17
>>
>>
>
> See my earlier suggestion. Before checking if it's an array, you should
> see if it's even set:
>
> if(isset($_POST['lunch']) && is_array($_POST['lunch']) &&
> count($_POST['lunch'])) {
> foreach ($_POST['lunch'] as $choice) {
> print "You want a $choice bun. <br>";
> }
> }
>
> BTW - <br/> is valid for xml but not html.
>
>
"&& count($_POST['lunch'])" seems superfluous here. If it's an array
(empty or not), then foreach will not issue a warning.
--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*****************************
Navigation:
[Reply to this message]
|