How to convert PHP array to JavaScript array?

JavascriptWeb DevelopmentFront End Technology

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', '');

Converting PHP array into JavaScript.

var arr = <?php echo json_encode($myArr); ?>;

Now, let’s finally learn how to access it to output the email −

Updated on 18-Jun-2020 12:30:17