Re: PHP arrays and javascript

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Marek Kilimajer wrote:

> 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) .'"';
> ?>);

Would this work the same for multidimensional arrays?

-- 
-Nick Peters

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux