Re: implode errors if array empty
| From: | Petar Nedyalkov | Date: | Wed, 22 Sep 2004 10:35:16 +0000 |
| Subject: | Re: implode errors if array empty | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-197544@lists.php.net to get a copy of this message | ||
Hello,
I suppose the $enterprise variable doesn't hold an empty array but is not
defined and because of this you get the error. Test with the following
example:
<?php
$array = array();
$comma_separated = implode(",", $array);
echo $comma_separated;
?>
It does not send any errors back. If you substitute $array = array(); with
$array = ""; you'll get a woarning: "Warning: implode(): Bad arguments. in
temp.php on line 4".
Just have in mind that when posting multiple select fields and no options are
selected - you simply have no corresponding value in the _POST array (or in
the $enterpise variable if you're using register_globals). There's no empty
array but nothing defined.
On Wednesday 22 September 2004 13:16, luke@lukem.co.uk wrote:
> hi there,
>
> i am using implode to get the contents of an array into a single variable:
>
> $enterprises = implode(",", $enterprise) //enterprise contains the array.
>
> however, if the array is empty (the user didnt select anything in the
> form), the implode function errors out.
>
> can anyone think of a way round this?
>
> many thanks,
>
> luke m.
--
Cyberly yours,
Petar Nedyalkov
Devoted Orbitel Fan :-)
---------------------------------------------------------------------
Orbitel - the New Generation Telecom! See www.orbitel.bg.