note 48 deleted from function.reset by sobak
| From: | sobak@php.net | Date: | Sat, 18 Apr 2020 19:23:22 +0000 |
| Subject: | note 48 deleted from function.reset by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-214505@lists.php.net to get a copy of this message | ||
Note Submitter: kk at shonline dot de
----
When used on a scalar or unset value, reset() spews warning messages. This is often a problem when
accessing arrays generated from HTML form input data: these are scalar or unset if the user
didn't enter sufficient information.
You can silence these error messages by prefixing an @ (at sign) to reset(), but it is better style
to protect your reset() and the following array traversal with an if (isset()). Example code:
<?php
if (isset($form_array)) {
reset($form_array);
while (list($k, $v) = each($form_array) {
do_something($k, $v);
}
}
?>