Answers for "js array to php 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

convert a php array into a javascript array

var js_array = [<?php echo '"'.implode('","',  $disabledDaysRange ).'"' ?>];
Posted by: Guest on February-25-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

Browse Popular Code Answers by Language