<?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. I want to increase $say' s value in javascript code. But not working. What Can I do?

You need to do the iteration on the server (via PHP). Since all four of your PHP array have the same number of elements, iterate over one of them and use that numeric index to retrieve the equivalent element from the other arrays. Try:

<?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"); 
?>
<script type="text/javascript"> 
var tipi = new Array();
var gun = new Array(); 
var ay = new Array();
var yil = new Array();
<?php
for($j=0,$limit=count($tipi);$j<$limit;$j++)
{
    echo 'tipi[',$j,']="',str_replace('"','\\"',$tipi[$j]),'";',PHP_EOL;
    echo 'gun[',$j,']="',str_replace('"','\\"',$gun[$j]),'";',PHP_EOL;
    echo 'ay[',$j,']="',str_replace('"','\\"',$ay[$j]),'";',PHP_EOL;
    echo 'yil[',$j,']="',str_replace('"','\\"',$yil[$j]),'";',PHP_EOL;
}
?>
</script>

It is work=) Thank you so much =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.