Rahmat Saepuloh Rahmat Saepuloh - 5 months ago 9
PHP Question

How to get data from multidimensional array encoded in json?

I have this JSON string:

{
"11153" : {
"sub" : {
"11411" : {
"id" : "994834",
"source_api" : "all",
"tanggal" : "2016-06-14",
"instansi_id" : "11411",
"belum" : "12",
"proses" : "23",
"selesai" : "7",
"parent_nid" : "11153",
"InstansiName" : "Dinas PSDA dan ESDM Kota Semarang",
"sub" : [],
"rtl" : "5.30"
},
}
}
}


How can I get
belum
,
proses
, and
selesai
values from this let me know?

Answer

Your data is in jsonn encoded format. So use json_decode() like below:-

<?php
$data = '{
    "11153" : {
        "sub" : {
            "11411" : {
                "id" : "994834",
                "source_api" : "all",
                "tanggal" : "2016-06-14",
                "instansi_id" : "11411",
                "belum" : "12",
                "proses" : "23",
                "selesai" : "7",
                "parent_nid" : "11153",
                "InstansiName" : "Dinas PSDA dan ESDM Kota Semarang",
                "sub" : [],
                "rtl" : "5.30"
            }
        }
    }
}'; // initial data

$new_array = json_decode($data,true); // decode data to convert it to array
echo "<pre/>";print_r($new_array); // print the array
echo $new_array[11153]['sub'][11411]['belum'];// you can print others like this 

Output:- https://eval.in/596111

Comments