I am getting an array in php, and send it to smarty .tpl file.
In smarty I would like to get that array in a java script variable .
How to do this . Please help me ...
I am getting an array in php, and send it to smarty .tpl file. In smarty I would like to get that array in a java script variable . How to do this . Please help me ... |
||||
|
simplest way is to use json:
json_encode() takes you php data and converts it into json, amd in our case its exactly what we need |
|||
|
I think it should simple like
|
|||
|
In php file just add like this
in template file use it like this
|
|||
|
It is better to use
if your array contains only integers the you can use |
|||
|
Since PHP is parsed prior to any JS, you can simply add the values from the PHP array into a JS function: So if you have this array in PHP:
Then you can use the following to initialize a JS array with the same values:
|
|||||||||
|