RE: [PHP] join() , can do that fast?
| From: | John W. Holmes | Date: | Mon, 07 Oct 2002 09:19:04 +0000 |
| Subject: | RE: [PHP] join() , can do that fast? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-119058@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: lallous [mailto:phplist@lgwm.org]
> Sent: Monday, October 07, 2002 6:09 AM
> To: php-general@lists.php.net
> Subject: [PHP] join() , can do that fast?
>
> Hello,
>
>
> I have:
> $x = array('str1','str2','str3');
>
> I want to convert that array to a valid javascript syntax as:
>
> var x = ['str1','str2','str3']
>
> I can do this in PHP:
>
> echo sprintf("x=[%s]", join(',', $x));
echo sprintf("x=['%s']", join("','", $x));
> but that would produce:
> x = [str1, str2, str3]
>
> is there is a fast way (other than doing a loop) to have join put
quote
> around each array value before joining? so final result looks like:
> ['str1','str2',...
---John Holmes...