Cara menggunakan php array to json
What is JSON?JSON stands for JavaScript Object Notation, and is a syntax for storing and exchanging data. Show
Since the JSON format is a text-based format, it can easily be sent to and from a server, and used as a data format by any programming language. PHP and JSONPHP has some built-in functions to handle JSON. First, we will look at the following two functions:
PHP - json_encode()The json_encode() function is used to encode a value to JSON format. ExampleThis example shows how to encode an associative array into a JSON object: $age = array("Peter"=>35, "Ben"=>37, "Joe"=>43); echo json_encode($age); Run Example » ExampleThis example shows how to encode an indexed array into a JSON array: $cars = array("Volvo", "BMW", "Toyota"); echo json_encode($cars); Run Example » PHP - json_decode()The json_decode() function is used to decode a JSON object into a PHP object or an associative array. ExampleThis example decodes JSON data into a PHP object: $jsonobj = '{"Peter":35,"Ben":37,"Joe":43}'; var_dump(json_decode($jsonobj)); Run Example » The json_decode() function returns an object by default. The json_decode() function has a second parameter, and when set to true, JSON objects are decoded into associative arrays. ExampleThis example decodes JSON data into a PHP associative array: $jsonobj = '{"Peter":35,"Ben":37,"Joe":43}'; var_dump(json_decode($jsonobj, true)); Run Example » PHP - Accessing the Decoded ValuesHere are two examples of how to access the decoded values from an object and from an associative array: ExampleThis example shows how to access the values from a PHP object: $jsonobj = '{"Peter":35,"Ben":37,"Joe":43}'; $obj = json_decode($jsonobj); echo $obj->Peter; Run Example » ExampleThis example shows how to access the values from a PHP associative array: $jsonobj = '{"Peter":35,"Ben":37,"Joe":43}'; $arr = json_decode($jsonobj, true); echo $arr["Peter"]; Run Example » PHP - Looping Through the ValuesYou can also loop through the values with a foreach() loop: ExampleThis example shows how to loop through the values of a PHP object: $jsonobj = '{"Peter":35,"Ben":37,"Joe":43}'; $obj = json_decode($jsonobj); foreach($obj as $key => $value) { Run Example » ExampleThis example shows how to loop through the values of a PHP associative array: $jsonobj = '{"Peter":35,"Ben":37,"Joe":43}'; $arr = json_decode($jsonobj, true); foreach($arr as $key => $value) { Run Example »
Konversi MySQL ke JSON Menggunakan PHP – hallo sahabat malasngoding.com, pada kesempatan ini saya akan membahas begaimana cara Konversi MySQL ke JSON Menggunakan PHP. yang harus kita ketahui terlebih dahulu apa itu json ? Konversi MySQL ke JSON Menggunakan PHPJson (Javascript Object Notation) merupakan salah satu format pertukaran data yang dikenal ringan, mudah di baca dan di tulis serta mudah di terjemahkan oleh komputer. adapun kelebihan dari json sendiri :
berikut format data Json:
oke, saya rasa untuk penjelasan Json dan format data json sendiri sudah bisa di pahami, untuk selanjutnya saya akan membuat sebuah contoh cara Konversi MySQL ke JSON Menggunakan PHP. maksudnya kita mempunyai data dalam mysql dan akan kita tampilkan data tersebut dalam format json. berikut membuat tabel dalam database :
membuat koneksi database mysql dengan php :
menampilkan data mysql dalam format json dengan php :
berikut tampilan dari hasil yang suddah kita buat tadinya : Konversi MySQL ke JSON Menggunakan PHP ok, sekian dulu tutorial Konversi MySQL ke JSON Menggunakan PHP. kita berjumpa kembali di lain waktu dengan materi yang baru. salam malasngoding Incoming search terms:
Tags:
cara membuat data json, crud php mysql json, format data json, json,
json adalah, konversi mysql ke json, Konversi MySQL ke JSON Menggunakan PHP, membuat api dengan php
mysql, membuat data json dengan php mysql, membuat json dengan php, mysql json, tutorial json php mysql,
tutorial membuat json dengan php TUTORIAL MENARIK LAINNYA Membuat laporan dalam bentuk PDF merupakan merupakah salah satu materi yang harus kita kuasai dalam proses pembuatan aplikasi. Kenapa demikian ? Hal ini karena hampir ... Export data ke
excel dengan PHP dalah salah satu model yang biasanya digunakan dalam membuat laporan berdasarkan referensi data dari MySQL. Export data ke excel ... Membuat QR Code Dengan PHP – Halo teman-teman, Selamat datang kembali di malasngoding.com. Pada materi tutorial ini kita akan belajar tentang Membuat QR Code Dengan ... Menghitung jumlah baris adalah salah satu teknik yang penting dalam berbagai bidang terutama dalam bidang pemrograman. Dalam pemrograman web, disini saya menggunakan pemrograman PHP untuk ...
|