seumpama terdapat 10 baris kode, baris pertama berupa request url (CURL), jika CURL mengalami request timeout, maka kode bukan akan terminate tetapi beralih menjalankan baris kode selanjutnya
http://www.dyn-web.com/tutorials/php-js/json/multidim-arrays.php
$food_groups = array(
'meat' => array(),
'vegetables' => array(
'leafy' => array('collard greens', 'kale', 'chard', 'spinach', 'lettuce'),
'root' => array('radish', 'turnip', 'potato', 'beet'),
'other' => array('brocolli', 'green beans', 'corn', 'tomatoes')
),
'grains' => array('bread', 'rice', 'oatmeal'),
'legumes' => array('kidney beans', 'lentils', 'split peas'),
'fruits' => array('apple', 'raspberry', 'pear', 'banana'),
'sweets' => array('cookies', 'brownies', 'cake', 'pie'),
);
{
"meat":[],
"vegetables":{
"leafy":["collard greens","kale","chard","spinach","lettuce"],
"root":["radish","turnip","potato","beet"],
"other":["brocolli","green beans","corn","tomatoes"]
},
"grains":["bread","rice","oatmeal"],
"legumes":["kidney beans","lentils","split peas"],
"fruits":["apple","raspberry","pear","banana"],
"sweets":["cookies","brownies","cake","pie"]
}
vegetables kenapa jadi Jsonobject? karena ada associative array didalamnya " 'leafy' => array() "
leafy kenapa jadi JsonArray? karena tidak ada associative array didalamnya
cat. associative array adalah array yang index nya berupa string
$output = json_decode(json_encode($stdclass_variable), true); //When TRUE, returned objects will be converted into associative arrays.
param 'true' untuk membuat agar property dari JSONString di convert ke associative array (array yang index nya string)
convert stdObject / array ke JSON String, contoh:
$data = ["nama"=>"irul","alamat"=>"malang","web"=>"http://tafsirul.web.id"];
echo json_encode($data);
hasilnya sudah berupa string, jadi jika ingin digunakan sebagai string, tidak perlu di stringify:
{"nama":"irul","alamat":"malang","web":"http:\/\/tafsirul.web.id"}