php file
$querySelectWordFilter = "SELECT * FROM badwordfilter";
$stmtSelectWordFilter = $conn->prepare($querySelectWordFilter);
$stmtSelectWordFilter->execute();
while($rowSelectWordFilter = $stmtSelectWordFilter->fetch()){
$Array[] = $rowSelectWordFilter["filterWord"];
}
foreach($Array as $val){
echo $val;
}
Javascript file
<script>
var filter = ['ass', 'evil','ugly'];
</script>
Question : Firstly,I select all the value from database and store it into array.But how can i pass the PHP array variable into JavaScript filter variable?
var filter = <?php echo json_encode($Array); ?>;
– Saty Mar 22 '16 at 6:07