Answers for "pass array from php to javascript"

PHP
1

convert php array to javascript array

<?php
    $vegetables = ['apple', 'strawberry', 'banana'];
?>

<script>
var arr = "<?php echo implode(",", $vegetables); ?>".split(",");
console.log(arr); //["apple", "strawberry", "banana"]
Vue.component('#app7', {
    props: arr,
    template: '<li>{{ item.text }}</li>'
})

</script>
Posted by: Guest on October-09-2021

Code answers related to "pass array from php to javascript"

Browse Popular Code Answers by Language