[英]Php Json Get Value Array Index?
I have this code: 我有以下代码:
{"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"}
How can get siparisler
id with array index? 如何获得带有数组索引的
siparisler
id?
$result2 = json_decode ($val,true);
return $result2[1][0];
I want to get that with array index because my JSON names are always different. 我想用数组索引来获取它,因为我的JSON名称总是不同的。
or how can i get second array name for if control ? 或如何获得if控件的第二个数组名称?
you could use array_values()
to normalize the arrays: 您可以使用
array_values()
标准化数组:
return array_values(array_values(json_decode($val, true))[1])[0];
array_values() returns all the values from the
array
and indexes the array numerically.array_values()返回
array
所有值,并对array
进行数字索引。
The same split into multiple statements to be more clear: 同样将其拆分为多个语句以使其更加清晰:
$result = json_decode($val, true);
$result = array_values($result)[1];
$result = array_values($result)[0];
return $result;
Or for PHP 5.3 and below: 或对于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.