+ 1
$ to declare variable in php & $ used as shortcut in JQuery, both in the same file, so the question is don't they get conflict?
All in all the code works fine.
4 Antworten
+ 3
As the other answers suggest, PHP and JavaScript do not share the same namespace even if they coexist in a single file. What you actually should be worried about is readability and separation of concerns.
Also note that if you include 2 different frameworks using <script> tags that use the same $ sign, there would be conflict and you may have to explicitly refer to 'jquery' instead of '#x27;
+ 3
There is no conflict because of the tags:
<script> for JQuery
<?php for PHP
+ 3
Php works inside <?php ...... ?>
jQuery works inside <script>
How it is possible to conflict both for $
+ 1
There is no conflict because JavaScript code goes between the <script> and </script> tags, and PHP code goes between the <?php and ?> tags.
<script>
// here, $ is a shortcut for jQuery
</script>
<?php
/* here, $ is the first character of a PHP variable */
?>