0

If we have a variable in php which holds a value then we can assign easily this value to js variable but the vice versa is possible?

For Assign php variable to js variable we use

 <?php $r = 1; ?>
 <script>
  var s = "<?php echo $r; ?>";
 </script>

But for assign js variable to php variable its not works

 <script>
  var s = 1;
 </script>
 <?php $r = echo "<script> s </script>"; ?>'

Not working

1 Answers1

-1

Generally, PHP is server side while Javascript is client side. You can do it by creating a browser cookie using Javascript and then use PHP to read that cookie.

Anyway, why do you want to do that?

Norman
  • 387
  • 2
  • 11