I've simplified the problem down as much as possible, I feel like this should work. The below script controls the autocomplete function and works as expected (if a user types 't', 'test' appears as a suggested input).
<script type="text/javascript">
$(function() {
var availableClients = ['test'];
$("#addClient").autocomplete({
source: availableClients,
});
});
</script>
However, if I set a PHP variable $test = "'test'" and replace 'test' in the original script with <?php echo $test; ?> the autocomplete script no longer works. Is there another way I can use a PHP variable as the autocomplete source or am I missing something?
EDIT: Here is the script with the PHP in it.
<script type="text/javascript">
$(function() {
var availableClients = [<?php echo $test; ?>];
$("#addClient").autocomplete({
source: availableClients,
});
});
</script>
And the only relevant PHP code is this.
$test = "'test'";
$testas well as the output it generates.