Re: Last array element not found
| From: | Robin Vickery | Date: | Wed, 15 Mar 2006 16:58:46 +0000 |
| Subject: | Re: Last array element not found | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-231953@lists.php.net to get a copy of this message | ||
On 15/03/06, Roman Rumisek <romanr@cbox.cz> wrote:
> Hi,
>
> this code fragment give following result in my error log:
>
> foreach($reg_array as $region_item)
> $tmp_reg_array[] = $region_item[0];
> $sel_region = explode(',', $_POST[CLIENT_REGION]);
> foreach($sel_region as $sel_region_item)
> if(!in_array($sel_region_item, $tmp_reg_array))
> {
> my_error_log("Unknown region: $sel_region_item, region array: ".
> var_export($tmp_reg_array, TRUE));
> header("Location: ".
> get_error_result(
> $state_def[$_SESSION[STATE_VAR]][STATE_REDIR_PAGE])
> );
> exit;
> }
It's more likely that you've got whitespace before or after the
region, especially if it's the last in the list that's always failing.
Try trimming the region before passing it to in_array().
Have you ever considered using braces around loop blocks?
-robin