JavaScript required
We’re sorry, but Coda doesn’t work properly without JavaScript enabled.
Skip to content
Dictionary Solution / Fix Bug
PHP
Database
VCS ( Git )
Json
FullStack
Queue / Antri
Devops
More
Share
Explore
Json PHP
Refrensi
Fungsi
json_decode
dan
json_encode
json_encode =
mengembalikan representasi JSON dari suatu nilai. Dengan kata lain, ia mengubah variabel PHP (berisi array) menjadi JSON
Data Yang Berupa Array
*
<?php
// array data
$arr
=
array
('a'
=> 1, 'b'
=> 2, 'c'
=> 3, 'd'
=> 4, 'e'
=> 5);
//meng encode data array
echo
json_encode
(
$arr
);
?>
_____
Result / Hasil
{
"a":1,
"b":2,
"c":3,
"d":4,
"e":5
}
json_decode =
untuk menerjemahkan string JSON agar mudah saat akan diolah. Dengan kata lain, mengubah string JSON menjadi variabel PHP
<?php
$json
= '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(
json_decode
(
$json
, true));
?>
_____
Result / Hasil
array
(5) {
["a"] => int(1)
["b"] => int(2)
["c"] => int(3)
["d"] => int(4)
["e"] => int(5)
}
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
Ctrl
P
) instead.