I have a question about using javaScript value in PHP:
var i; <br>
for(i=0;i<4;i++){ <br>
alert("echo $MarkA[i]");<br>
}
$MarkA
is a PHP array
I want to know that how can I using the javascript value 'i' in PHP code.
Thanks.
var i; <br>
for(i=0;i<4;i++){ <br>
alert("echo $MarkA[i]");<br>
}
$MarkA
is a PHP array
I want to know that how can I using the javascript value 'i' in PHP code.
Thanks.
You cannot use client side script variable into server side script. But you can parse the PHP array using the below method. No need javascript increment variable.
<?php $MarkA = array(1,2,3,4);?>
<script>
var json = JSON.parse("<?php echo json_encode($MarkA);?>");
$.each(json,function (i,item) {
console.log(item);
});
</script>