Pass PHP Array to JavaScript

Last Updated On Monday 4th Oct 2021
	$peoples = array(
    array(
        'name' => 'Halliday',
        'email' => 'halliday@example.com'
    ),
    array(
        'name' => 'Jesse',
        'email' => 'jesse@example.com'
    ),
    array(
        'name' => 'Aiden',
        'email' => 'aiden@example.com'
    )
);
?>
	
	<script type="text/javascript">
    let peoplesArr = <?php echo json_encode($peoples);?>;
    console.log(peoplesArr[1].name);
    // Output: Jesse
</script>
	
	<script type="text/javascript">
    console.log(peoplesArr[2][1]);
    // Output: aiden@example.com
</script>