Re: PHP arrays and javascript
| From: | Marek Kilimajer | Date: | Fri, 26 Nov 2004 21:43:15 +0000 |
| Subject: | Re: PHP arrays and javascript | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-202919@lists.php.net to get a copy of this message | ||
Nick Peters wrote:
Hey, i know this probally a simple question, but it has been stumping me for quite some time now. How do i pass a php array to a javascript? i tryed: <script language="javascript"> var myarray = new Array(<?PHP echo $myarray; ?>); </script> but it didn't work. Anybody got any ideas? thanks in advance.For integers and floats: var myarray = new Array(<?PHP echo implode(', ', $myarray); ?>); For strings: var myarray = new Array(<?PHP echo '"'. implode('", "', $myarray) .'"'; ?>);