Last active
September 1, 2023 17:04
-
-
Save hbisneto/48c5343191c6072ffce2f871d8cb4889 to your computer and use it in GitHub Desktop.
AssocArray.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$arrayAssociativo = array( | |
"nome" => "João", | |
"idade" => 30, | |
"cidade" => "São Paulo" | |
); | |
$json = json_encode($arrayAssociativo); | |
?> | |
<script> | |
var objeto = JSON.parse('<?php echo $json; ?>'); | |
console.log(objeto.nome); // Saída: João | |
console.log(objeto.idade); // Saída: 30 | |
console.log(objeto.cidade); // Saída: São Paulo | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment