Calling Javascript function in PHP while passing PHP variables into the function

后端 未结 2 807
囚心锁ツ
囚心锁ツ 2020-12-21 16:25

I\'m experiencing a problem when calling a JavaScript function inside PHP code and trying to pass my PHP variables as parameters into the function. While it seems really sim

相关标签:
2条回答
  • 2020-12-21 16:44

    I think you should use curly braces to better distinguish variables in a string. Just wrap them like this:

    echo "<script type='text/javascript'>functionName({$var1}, {$var2}, {$var3});</script>"
    
    0 讨论(0)
  • 2020-12-21 16:57

    Single quotes litterally puts your $var as $var. While double quotes puts your $var in 0 1 or 2

    echo "<script type='text/javascript'>functionName('$var1', '$var2', '$var3');</script>"
    
    0 讨论(0)
提交回复
热议问题