-8

i have a data like this

{
"tanggal":"2015-05-31",
"idSupplier":"15",
"totalBeli":1680000,
"dataBarang":[
    {
        "kode":"111",
        "nama":"asus",
        "jenisid":"1",
        "jenisnama":"Flashdisk",
        "hargasatuan":"90000",
        "hargajual":"120000",
        "jumlahstok":"12",
        "stockmin":"10",
        "satuan":"unit"
    },
    {
        "kode":"124",
        "nama":"cliptec",
        "jenisid":"1",
        "jenisnama":"Flashdisk",
        "hargasatuan":"50000",
        "hargajual":"100000",
        "jumlahstok":"12",
        "stockmin":"2",
        "satuan":"unit"
    }
]

}

and how to get value array in object with PHP.. for example i need value from object dataBarang

thanks before

Faiz Rasool
  • 1,379
  • 1
  • 12
  • 20
user3811024
  • 31
  • 2
  • 9

1 Answers1

0

Decode your json array then get values by using following code:

$jsonArr = json_decode($json);   
echo '<pre>';print_r($jsonArr);echo '</pre>';

// To fetch object     
echo '<pre>';print_r($jsonArr->dataBarang);echo '</pre>';

// To fetch single array from object 
echo '<pre>';print_r($jsonArr->dataBarang[0]);echo '</pre>';

// To Array -> object -> array -> object by array key 
echo '<pre>';print_r($jsonArr->dataBarang[0]->kode);echo '</pre>';
Noman
  • 4,088
  • 1
  • 21
  • 36