Bagaimana cara mengambil data json menggunakan perulangan php

datanyaBagaimana jika saya ingn mengambil data merchan_invoice, merchant_id, transaction_amount, dan transaction_date

avatar nfa
@nfa

8 Kontribusi 3 Poin

Diperbarui 2 tahun yang lalu

2 Jawaban:

<div>Decode dulu jd array lakukan sisanya penelusuran data array dan looping data tersebut<br><br></div>

avatar logika
@logika

19 Kontribusi 8 Poin

Dipost 2 tahun yang lalu

Jawaban Terpilih

<div>Gunakan json_decode dari php untuk mengdecode atau mengekstrak json datanya<br><br></div><pre>&lt;?php $json = '{ "data": { "status": 200, "orders": [{ "complete": [{ "merchant_invoice": "111111", "merchant_id": "1", "transaction_amount": "10.500", "transaction_time": "17:44:20" }, { "merchant_invoice": "111111", "merchant_id": "1", "transaction_amount": "10.500", "transaction_time": "17:44:20" }, { "merchant_invoice": "111111", "merchant_id": "1", "transaction_amount": "10.500", "transaction_time": "17:44:20" }] }] } }';

$json_array = json_decode($json, true);

$arr = $json_array['data']['orders'][0]['complete'];

<em>foreach</em>($arr as $key=&gt;$value){ echo "merchant_invoice : " . $value['merchant_invoice'] . " "; echo "merchant_id : " . $value['merchant_id'] . " "; echo "transaction_amount : " . $value['transaction_amount'] . " "; echo "transaction_time : " . $value['transaction_time'] . " "; } <br></pre><div><br></div>

avatar lionkip
@lionkip

65 Kontribusi 49 Poin

Dipost 2 tahun yang lalu

Tanggapan

Terimakasih mas udah bisa

sama-sama kak

Login untuk ikut Jawaban