Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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..

share|improve this question
4  
Please show the code you've tried so far :) –  Paul D. 2 days ago
 
refer below link, this make it easy stackoverflow.com/questions/5618925/… –  manikandan 2 days ago
add comment

put on hold as off-topic by Alessandro Minoccheri, Mr. Alien, KooiInc, Suresh Kamrushi, Quentin 2 days ago

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist" – Alessandro Minoccheri, Suresh Kamrushi, Quentin
  • "Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance." – Mr. Alien, KooiInc
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 1 down vote accepted

Convert your PHP array to JS Object (in JSON).

var obj = <?= json_encode($phpArr); ?>;

myAwesomeFunction(obj);
share|improve this answer
3  
you should avoid using <?= instead use <?php echo –  Suresh Kamrushi 2 days ago
2  
Whay you think so? It's easy for me. And my servers are always have short_open_tag=1. –  plutov 2 days ago
2  
short_open_tag does not relate to short echo tag since PHP 5.4 –  Royal Bg 2 days ago
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 2 days ago
 
@plutov: Wuss :) You were right. Why change it? –  cHao 2 days ago
show 2 more comments

Not the answer you're looking for? Browse other questions tagged or ask your own question.