I would like to use php variable in my javascript. This is what I currently have and is working just fine:
<?php
$test = '"test1","test2",test3"';
?>
<script type="text/javascript">
var values = [<?php echo $test; ?>],
valueToUse = values[Math.floor(Math.random() * values.length)];
alert(valueToUse);
</script>
However, if I use values that are retrieved from a database, this code will not work. Both variables contain exactly same values and are string type.