JSON encode PHP

PHP has some built-in functions to handle JSON. Objects in PHP can be converted into JSON by using the PHP function json_encode():

PHP file

<?php
$data->name = "John";
$data->age = 30;
$data->city = "New York";

echo $json_data = json_encode($data);

?>

Result:

{"name":"John","age":30,"city":"New York"}

JSON Array PHP

$age = array("Peter"=>35, "Ben"=>37, "Joe"=>43);

echo json_encode($age);

Result:

{"Peter":35,"Ben":37,"Joe":43}
READ :  Tipe Data PHP + Contoh / PHP Dasar
Topic : Web | Tags : , , ,
Author : Andreas

Publisher konten, aktif membuat artikel informatif membantu pembaca memahami tren terbaru secara lebih jelas dan mudah dipahami.

Editor : SEOSatu

Bertanggung jawab atas proses penyuntingan, verifikasi, dan optimasi pada setiap artikel. Memastikan konten akurat, relevan, dan sesuai standar kualitas.