![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert PHP array to JavaScript array?
You can use PHP array in JavaScript. It works for the single as well as the multidimensional array. Use the json_encode() method to achieve this.
Let’s say Our PHP array is −
$myArr = array('Amit', 'amit@example.com');
Converting PHP array into JavaScript.
<script> var arr = <?php echo json_encode($myArr); ?>; </script>
Now, let’s finally learn how to access it to output the email −
document.write(arr[1]);
Advertisements