I want to get data from foreach loop to variable of javascript ? Then I try some method to get and it work but it not going to separate array it's go as a one value. Can someone help me ??
Here is my code:
<script>
<?php $var = array('array1','array2'); ?>
var x = ['<?php foreach($var as $data){ echo $data } ?>'];
</script>
Then it return me: ['array1array2
]
In this I want show me like this:
['array1', 'array2'];
thank for your help !!!