Why am I unable to assign a php variable like this to jquery?
So if my php variable was
$amounts = 2,4,5
var amountFinal = <?php echo $amounts; ?>;
alert(JSON.stringify(<?php echo $amounts; ?>));, it prints `2`
var amountFinal = "<?php echo $amounts; ?>"; alert(amountFinal);
I dont understand what you mean by you second question?
ALSO, in php how do I break 2,4,5 into just 2, 4, 5?
Do you mean you want to make it into an array or you want to add some spaces?
2 4 5 you can do
$originalString = '2,4,5'; list($one,$two,$three) = explode(',', $originalString); echo $one; echo $two; echo $three;
Or add them to an array
$originalString = '2,4,5'; $array = explode(',', $originalString);