How can i print php variable in jquery?

By Hardik Savani | February 8, 2016 | | 39907 Viewer | Category : PHP Javascript jQuery


If you are working on php and you need to print your php variable inside the javascript then you can simple get value. you can use "" for get value of php variable. in following example you can see :

Example:

<script type="text/javascript">

var my_var = "<?php echo $my_variable; ?>";

console.log(my_var);

</script>

OR

<script type="text/javascript">

var my_var = <?php echo $my_variable; ?>;

console.log(my_var);

</script>

But, you can use on php file, Not on js file.



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.