![](/img/trans.png)
[英]How can I get array form file json and arrage Index value and result return array json [WITH PHP]
[英]Php Json Get Value Array Index?
我有以下代碼:
{"DT_RowId":"row_8","siparisler":{"id":"8","tarih":"14-12-2015","uid":"118","mid":"4","satis_fiyati":"5","adet":"7","odeme":"1","olusturan":"ares","sonduzenleyen":""},"urunler":{"urun_adi":"BANNER 100 AH","stok_kodu":"10010"},"musteriler":{"unvan":"3A Otomotiv San. Tic. Ltd. \u015eti."},"kdvsiz":"4.23728813559","kdv":"0.762711864407","top":"35"}
如何獲得帶有數組索引的siparisler
id?
$result2 = json_decode ($val,true);
return $result2[1][0];
我想用數組索引來獲取它,因為我的JSON名稱總是不同的。
或如何獲得if控件的第二個數組名稱?
您可以使用array_values()
標准化數組:
return array_values(array_values(json_decode($val, true))[1])[0];
array_values()返回
array
所有值,並對array
進行數字索引。
同樣將其拆分為多個語句以使其更加清晰:
$result = json_decode($val, true);
$result = array_values($result)[1];
$result = array_values($result)[0];
return $result;
或對於PHP 5.3及以下版本:
$result = json_decode($val, true);
$result = array_values($result);
$result = array_values($result[1]);
return $result[0];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.