Postingan lainnya
Shorting data json dengan php
nik yang di inputkan = 3320081505930003 atas nama IMAM MAHYUDIN,
$jsonDataEncoded = json_encode($jsonData); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//hasil ditransfer curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Accept: application/json' )); $result = curl_exec($ch); curl_close($ch); echo $result;//hasil berupa file json echo "
"; echo "
";
$data = json_decode($result, true);
foreach ($data['content'] as $va) { echo "Nama Lengkap = " $va['NAMA_LGKP']."
"; } }
hasil =
{"content":[{"DUSUN":null,"NAMA_LGKP":"IMAM MAHYUDIN","STAT_HBKEL":"ANAK","JENIS_PKRJN":"PELAJAR/MAHASISWA","PDDK_AKH":"TAMAT SD/SEDERAJAT","TMPT_LHR":"JEPARA","STATUS_KAWIN":"BELUM KAWIN","JENIS_KLMIN":"LAKI-LAKI","NO_KK":3320081008051332,"NIK":3320081505930003,"KAB_NAME":"JEPARA","NAMA_LGKP_AYAH":"AKROM","KEC_NAME":"BANGSRI","NO_RW":5,"NO_KEL":2012,"NO_RT":4,"KODE_POS":59453,"NO_KEC":8,"ALAMAT":"BANJARAGUNG","NO_PROP":33,"NAMA_LGKP_IBU":"ZUBAIDAH","PROP_NAME":"JAWA TENGAH","NO_KAB":20,"TGL_LHR":"1993-05-15","KEL_NAME":"BANJARAGUNG"},{"DUSUN":null,"NAMA_LGKP":"AKROM","STAT_HBKEL":"KEPALA KELUARGA","JENIS_PKRJN":"PERDAGANGAN","PDDK_AKH":"TAMAT SD/SEDERAJAT","TMPT_LHR":"JEPARA","STATUS_KAWIN":"KAWIN","JENIS_KLMIN":"LAKI-LAKI","NO_KK":3320081008051332,"NIK":3320081411510001,"KAB_NAME":"JEPARA","NAMA_LGKP_AYAH":"SANIBAN","KEC_NAME":"BANGSRI","NO_RW":5,"NO_KEL":2012,"NO_RT":4,"KODE_POS":59453,"NO_KEC":8,"ALAMAT":"BANJARAGUNG","NO_PROP":33,"NAMA_LGKP_IBU":"MUSRIPAH","PROP_NAME":"JAWA TENGAH","NO_KAB":20,"TGL_LHR":"1951-11-14","KEL_NAME":"BANJARAGUNG"},{"DUSUN":null,"NAMA_LGKP":"ZUBAIDAH","STAT_HBKEL":"ISTRI","JENIS_PKRJN":"MENGURUS RUMAH TANGGA","PDDK_AKH":"TAMAT SD/SEDERAJAT","TMPT_LHR":"JEPARA","STATUS_KAWIN":"KAWIN","JENIS_KLMIN":"PEREMPUAN","NO_KK":3320081008051332,"NIK":3320084710550001,"KAB_NAME":"JEPARA","NAMA_LGKP_AYAH":"MUHTAR ","KEC_NAME":"BANGSRI","NO_RW":5,"NO_KEL":2012,"NO_RT":4,"KODE_POS":59453,"NO_KEC":8,"ALAMAT":"BANJARAGUNG","NO_PROP":33,"NAMA_LGKP_IBU":"KASMIRAH","PROP_NAME":"JAWA TENGAH","NO_KAB":20,"TGL_LHR":"1955-10-07","KEL_NAME":"BANJARAGUNG"}],"lastPage":true,"numberOfElements":3,"sort":null,"totalElements":3,"firstPage":true,"number":0,"size":3}
Nama Lengkap = IMAM MAHYUDIN Nama Lengkap = AKROM Nama Lengkap = ZUBAIDAH
bagaimana cara shorting agar yang tampil hanya nama yang sesuai dengan nik yg diinput..?
Tanggapan
itu curl API nya kemana bro?
2 Jawaban:
Gunakan fasilitas sorting dari PHP saja.
sort() - sort arrays in ascending order rsort() - sort arrays in descending order asort() - sort associative arrays in ascending order, according to the value ksort() - sort associative arrays in ascending order, according to the key arsort() - sort associative arrays in descending order, according to the value krsort() - sort associative arrays in descending order, according to the key
tapi agak ribet !!! karena harus dibuat array satu dimensi dl.
Yang paling simple itu datanya di simpan dulu ke database, kemudian baru disorting.
bisa taruh pengecekan di dalam fornya <pre> $nikinput = '3320081505930003' foreach ($data['content'] as $va) { if($va['NIK']==$nikinput) echo "Nama Lengkap = " $va['NAMA_LGKP']."</br>"; } </pre>