0
<?php $say=0 ?>

<script> 
for(var j=0;j<limit;j++)
          {
              tipi[j] = " <?php echo "$tipi[$say]" ?> ";
              gun[j] = " <?php echo "$gun[$say]" ?> ";
              ay[j] = " <?php echo "$ay[$say]" ?> ";
              yil[j] = " <?php echo "$yil[$say]" ?> ";

                    <?php $say++;  ?>
          }
<script/>

//I want to increase $say in javascipt. But not working. $say 's value is 0 everytime. What can I do?

Edited by bilal.saim

3
Contributors
3
Replies
5
Views
4 Years
Discussion Span
Last Post by diafol
0

PHP is processed by the server and JS as processed by the browser. By the time your javascript loop runs PHP has already been fully processed and you cannot modify PHP variables from within JS, you'll have to either do it entirely in JS or PHP not a combination of the two. What is it you're trying to accomplish?

0
<?php 
$tipi = array("asd","222","dda","xcs"); 
 $gun = array("qwe","vvv","zzz","bffg"); 
 $ay = array("asd","bbb","23a","wqe"); 
 $yil=array("zzz","sad","cxc","zxca"); 

$say=0 ?>

<script> 

var tipi = new Array();
  var gun = new Array(); 
  var ay = new Array();
  var yil = new Array();

for(var j=0;j<4;j++)
          {
              tipi[j] = " <?php echo "$tipi[$say]" ?> ";
              gun[j] = " <?php echo "$gun[$say]" ?> ";
              ay[j] = " <?php echo "$ay[$say]" ?> ";
              yil[j] = " <?php echo "$yil[$say]" ?> ";

                    <?php $say++;  ?>
          }
</script>

//I have arrays in php code. I want to transfer this values in javascript code.

Edited by bilal.saim

0

php variables can be tranferred to js no prob - as you've done.
js vars to php is more difficult - due to php running on server and js running on client - so you can use ajax to do this if you really need to.

However, php vars are lost as soon as the ajax call is done (just like a page call) - so unless you store data in sessions, cookies, DBs etc, it could be a lot of hard work without any benefit.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.