Ads by ProfitSence
Close

Pass PHP Array to JavaScript

Last Updated on Wednesday 5th Oct 2022
			
					$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>