Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Passing PHP Arrays to JavaScript

<?php
// php array
$fruits = array('apple', 'orange', 'mango', 'banana', 'strawberry');
?>
<script type="text/javascript">
// use php implode function to build string for JavaScript array literal
var fruits = <?php echo '["' . implode('", "', $fruits) . '"]' ?>;
// ["apple", "orange", "mango", "banana", "strawberry"]
</script>
Source by www.dyn-web.com #
 
PREVIOUS NEXT
Tagged: #Passing #PHP #Arrays #JavaScript
ADD COMMENT
Topic
Name
4+6 =