Answers for "make php array into javascript array"

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
0

dump php array into javascript array

//in js do this
var masterarray =  <?php echo '["' . implode('", "', $masterarray) . '"]' ?>;
Posted by: Guest on November-02-2020

Code answers related to "make php array into javascript array"

Browse Popular Code Answers by Language