I need to pass an array as a function argument from php to js.I need a way to pass them to the function.Can anyone please help me with this. Thanks a lot..
Asked
Active
Viewed 84 times
3
-
4Please show the code you've tried so far :) – Paul D. Dec 26 '13 at 10:51
-
refer below link, this make it easy *http://stackoverflow.com/questions/5618925/convert-php-array-to-javascript* – manikandan Dec 26 '13 at 10:59
1 Answers
1
Convert your PHP array to JS Object (in JSON).
var obj = <?= json_encode($phpArr); ?>;
myAwesomeFunction(obj);

Alex Pliutau
- 21,392
- 27
- 113
- 143
-
3
-
2Whay you think so? It's easy for me. And my servers are always have `short_open_tag=1`. – Alex Pliutau Dec 26 '13 at 10:55
-
2
-
3`echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. Prior to PHP 5.4.0, this short syntax only works with the short_open_tag configuration setting enabled.` This means, 5.4.0 and more, you can write `=` even your short_open_tag is 0. So it's not poor practice. It's even better one. – Royal Bg Dec 26 '13 at 11:00
-
-
-