I’m trying to assign a php array of image filenames to a javascript array. Here’s what I got so far:
<script src="jq.js"></script>
<?php
$dir = 'images';
$images = scandir($dir);
$true_images = array();
foreach($images as $k=>$v){
if(is_file('images/'.$v)){
$true_images[] = $v;
}
}
?>
<script>
$(function(){
var image_array = Array(<?php echo implode(',', $true_images); ?>);
alert(image_array);
});
</script>
But I get the following error in firebug:
identifier starts immediately after numeric literal
Please help, thanks in advance
You must input your string array into “” or ”
try this