Postingan lainnya
Bagaimana cara menampilkan data di array multidimesi ?
ane punya data array seperti ini, ane pengen nampilkan data service
$datas = array(
array('code' => 'jne', 'name' => 'Jalur Nugraha Ekakurir (JNE)', 'costs' =>
array(
array('service' => 'OKE', 'description' => 'Ongkos Kirim Ekonomis', 'cost' =>
array(
array('value' => 42000, 'etd' => '4-5', 'note' => '')
)
)
,
array('service' => 'REG', 'description' => 'Layanan Reguler', 'cost' =>
array(
array('value' => 48000, 'etd' => '2-3', 'note' => '')
)
),
array('service' => 'YES', 'description' => 'Yakin Esok Sampai', 'cost' =>
array(
array('value' => 104000, 'etd' => '1-1', 'note' => '')
)
)
) )
);
dd($datas);
hasilnya seperti ini <a href='https://drive.google.com/file/d/14G3V9OpgWBML3sEacqqTYzMVuL32Psf2/view?usp=sharing '>https://drive.google.com/file/d/14G3V9OpgWBML3sEacqqTYzMVuL32Psf2/view?usp=sharing </a>
pertanyaan ane, gimana cara menampilkan data // service : xxx dan value : xxx // dengan menggunakan foreach??? mastah tolong bantuannya
0
2 Jawaban:
Jawaban Terpilih
foreach ($datas as $data) {
foreach ($data['costs'] as $service) {
print_r($service['service'] . ':');
foreach ($service['cost'] as $cost) {
print_r($cost['value'] . ', ');
}
}
}
atau ini
foreach ($datas as $data) {
foreach ($data['costs'] as $service) {
print_r($service['service'] . ':');
print_r($service['cost'][0]['value'] . ', ');
}
}
0