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

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by bilal.saim
1

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>
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.