I am using the following to convert a php array to javascript. var TextsArray = new Array(<?php foreach($TextsArray as $Text) { echo "'$Text',"; } ?>); PHP: The output of this statement is: var TextsArray = new Array('Your Text Here',); Code (markup): This generated line creates a syntax error, is it because of the single quotes???
No it's because of the comma. You need to check if you're on the last item of the array in php and not put the comma in. Just start an int counter and compare it to the length of the php array, if they are equal, don't echo the comma.