<script type="text/javascript" >
var arrayjs = <?php $arrayphp = array(1,3,5,6,7,10); ?>
//each? for? with jQuery {
console.log(num);
}
</script>
I have array in PHP. How can i get this for jQuery and showing with loop each or for?
<script type="text/javascript" >
var arrayjs = <?php $arrayphp = array(1,3,5,6,7,10); ?>
//each? for? with jQuery {
console.log(num);
}
</script>
I have array in PHP. How can i get this for jQuery and showing with loop each or for?
<script type="text/javascript">
var arrayjs = <?= json_encode(array(1,3,5,6,7,10)) ?>;
for(var i=0; i<arrayjs.length; ++i) {
console.log(arrayjs[i]);
}
</script>
There is no foreach in JavaScript. You have to do it old-school with indexes.
To pass a PHP variable to JS, use json_encode.
Edit: You can use $.each if you're using jQuery.
for (x in object) function?